Sha256: 37a48dc96541d37a0f848fa7147e78fadec2b7339b6fc497b9fb06179dd359ad
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 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 VarTag < 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['var'] "genit[var='#{var_name}']" end def get_variable_value filename = File.join(@working_dir, 'pages', @filename) doc = HtmlDocument.open filename doc.at_css("genit[var='#{@tag['var']}']").inner_html end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
genit-0.5 | lib/genit/var_tag.rb |