lib/genit/page_compiler.rb in genit-0.4.1 vs lib/genit/page_compiler.rb in genit-0.5
- old
+ new
@@ -1,9 +1,7 @@
# -*- encoding: utf-8 -*-
-require 'fileutils'
-
module Genit
# Compile a single page.
class PageCompiler
@@ -17,50 +15,34 @@
@template = XmlDocument.open(File.join(@working_dir, 'templates/main.html'))
end
# Public: Compile the page.
#
- # Returns a Nokogiri::HTML document.
+ # Returns a Nokogiri::XML document.
def compile
- genit_tags = HtmlDocument.genit_tags_from @template
- genit_tags.each {|tag| process_tag tag }
- @template
+ compile_body
+ compile_head
end
private
- def process_tag tag
- case tag['class']
- when 'pages' then tag_pages
- when 'menu' then tag_menu
+ def compile_body
+ genit_tags_in_template.each do |tag|
+ tp = TagProcessor.new(@working_dir, @template, @filename, tag)
+ @template = tp.process
end
+ builder = BodyLinkBuilder.new @template
+ @template = builder.build_for_page @filename
end
- # Remplace la page au sein du template
- def tag_pages
- builder = Builder.new(@template)
- @template = builder.replace('genit.pages', page_content)
+ def compile_head
+ builder = HeadLinkBuilder.new @template
+ builder.build_for_page @filename
end
- def page_content
- filename = File.join(@working_dir, 'pages', @filename)
- HtmlDocument.build_page_content filename, @working_dir
- end
-
- def tag_menu
- build_menu
- replace_menu_into_template
- end
-
- def build_menu
- menu = XmlDocument.open(File.join(@working_dir, "templates/menu.html"))
- builder = Builder.new(menu)
- @menu = builder.select_menu(@filename)
- end
-
- def replace_menu_into_template
- builder = Builder.new(@template)
- @template = builder.replace('genit.menu', @menu.to_html)
+ # Returns all <genit> tags found in the template.
+ def genit_tags_in_template
+ HtmlDocument.genit_tags_from @template
end
end
end