[Groonga-commit] ranguba/packnga at 23f4707 [master] Don't require template files

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Oct 20 18:38:19 JST 2014


Kouhei Sutou	2014-10-20 18:38:19 +0900 (Mon, 20 Oct 2014)

  New Revision: 23f47073aca9d36a19b1b4f2f67963ad3a6c8f59
  https://github.com/ranguba/packnga/commit/23f47073aca9d36a19b1b4f2f67963ad3a6c8f59

  Message:
    Don't require template files

  Modified files:
    lib/packnga/reference-task.rb

  Modified: lib/packnga/reference-task.rb (+18 -6)
===================================================================
--- lib/packnga/reference-task.rb    2014-10-19 18:50:12 +0900 (bbd08a7)
+++ lib/packnga/reference-task.rb    2014-10-20 18:38:19 +0900 (2da74bb)
@@ -308,17 +308,28 @@ module Packnga
       content = content.gsub(/lang="en"/, "lang=\"#{language}\"")
 
       title = nil
-      content = content.gsub(/<title>(.+?)<\/title>/m) do
+      content = content.gsub(/<title>(.+?)<\/title>/m) do |matched_text|
         title = $1
-        templates[:head].result(binding)
+        head_template = templates[:head]
+        if head_template
+          head_template.result(binding)
+        else
+          matched_text
+        end
       end
 
-      content = content.gsub(/<body(?:.*?)>/) do |body_start|
-        "#{body_start}\n#{templates[:header].result(binding)}\n"
+      header_template = templates[:header]
+      if header_template
+        content = content.gsub(/<body(?:.*?)>/) do |body_start|
+          "#{body_start}\n#{header_template.result(binding)}\n"
+        end
       end
 
-      content = content.gsub(/<\/body/) do |body_end|
-        "\n#{templates[:footer].result(binding)}\n#{body_end}"
+      footer_template = templates[:footer]
+      if footer_template
+        content = content.gsub(/<\/body/) do |body_end|
+          "\n#{footer_template.result(binding)}\n#{body_end}"
+        end
       end
 
       content
@@ -326,6 +337,7 @@ module Packnga
 
     def erb_template(name)
       file = File.join("doc/templates", "#{name}.html.erb")
+      return nil unless File.exist?(file)
       template = File.read(file)
       erb = ERB.new(template, nil, "-")
       erb.filename = file
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index