Class: Genit::ClassFragmentTag

Inherits:
Tag
  • Object
show all
Defined in:
lib/genit/tags/class_fragment_tag.rb

Overview

Replace the <genit class=“fragment”/> in the template.

Instance Method Summary collapse

Methods inherited from Tag

#replace_tag_into_template!

Constructor Details

#initialize(working_dir, template, filename, tag) ⇒ ClassFragmentTag

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



14
15
16
17
18
19
20
# File 'lib/genit/tags/class_fragment_tag.rb', line 14

def initialize working_dir, template, filename, tag
  super working_dir, template, filename, tag
  @file = @tag['file']
  error "Incomplete #{@tag}" unless @tag.key?('file')
  @full_path = File.join(@working_dir, FRAGMENTS_DIR, @file)
  error "No such file #{@tag}" unless File.exists?(@full_path)
end

Instance Method Details

#processObject

Public: Do the replacement.

Returns the template as a Nokogiri::XML::Document



25
26
27
28
29
# File 'lib/genit/tags/class_fragment_tag.rb', line 25

def process
  fragment = HtmlDocument.build_page_content(@full_path, @working_dir)
  css_rule = "genit.fragment[file='#{@file}']"
  replace_tag_into_template! css_rule, fragment.to_s
end