Sha256: f7d94ba1c55232f25c21926e290b101534e8958e94154d5f6ed94c2c2af3442e
Contents?: true
Size: 1.35 KB
Versions: 2
Compression:
Stored size: 1.35 KB
Contents
# -*- encoding: utf-8 -*- module Genit # A Genit tag that represents a variable. # For example, in the template you have: <genit var="page_title"/>, # and in the page you have: <genit var="page_title">My Title</genit>. class HereTag < Tag # Public: Constructor. # # working_dir - The String working directory, where live the project. # template - The Nokogiri::XML::Document into which we process the tag. # filename - The String name of the page # tag - The tag to process as a Nokogiri::XML::Element def initialize working_dir, template, filename, tag super working_dir, template, filename, tag end # Public: Replace a variable in the template. The variable content is found # in the tag in the page. # # Returns the template as a Nokogiri::XML::Document def process replace_tag_into_template! get_css_rule, get_variable_value @template end private def get_css_rule var_name = @tag['here'] "genit[here='#{var_name}']" end def get_variable_value doc = HtmlDocument.open_fragment File.join(@working_dir, 'pages', @filename) elem = doc.at_css "genit[what='#{@tag['here']}']" if elem.nil? warning "here without what #{@tag}" "" else elem.inner_html end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
genit-1.0.1 | lib/genit/tags/here_tag.rb |
genit-1.0 | lib/genit/tags/here_tag.rb |