class Genit::HereTag

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>.

Public Class Methods

new(working_dir, template, filename, tag) click to toggle source

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

Calls superclass method
# File lib/genit/tags/here_tag.rb, line 15
def initialize working_dir, template, filename, tag
  super working_dir, template, filename, tag
end

Public Instance Methods

process() click to toggle source

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

# File lib/genit/tags/here_tag.rb, line 23
def process
  replace_tag_into_template! get_css_rule, get_variable_value
  @template
end

Private Instance Methods

get_css_rule() click to toggle source
# File lib/genit/tags/here_tag.rb, line 30
def get_css_rule
  var_name = @tag['here']
  "genit[here='#{var_name}']"
end
get_variable_value() click to toggle source
# File lib/genit/tags/here_tag.rb, line 35
def get_variable_value
  file = File.join(@working_dir, PAGES_DIR, @filename)
  doc = HtmlDocument.open_fragment file
  html_or_nothing_from(doc.at_css("genit[what='#{@tag['here']}']"))
end
html_or_nothing_from(element) click to toggle source
# File lib/genit/tags/here_tag.rb, line 41
def html_or_nothing_from element
  if element.nil?
    warning "here without what #{@tag}"
    ""
  else
    element.inner_html
  end
end