Class: Genit::Fragment

Inherits:
Object
  • Object
show all
Defined in:
lib/genit/documents/fragment.rb

Overview

Replace each fragment in a page.

Instance Method Summary collapse

Constructor Details

#initialize(file, working_dir) ⇒ Fragment

Public: Constructor.

file - Full String filename of the page. working_dir - The String working directory, where live the project.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/genit/documents/fragment.rb', line 12

def initialize file, working_dir
  
  @page = HtmlDocument.open_fragment file
  @working_dir = working_dir
  HtmlDocument.genit_tags_from(@page).each do |tag|
    case tag['class']
      when 'fragment'
        @file = tag['file']
        error "Incomplete #{tag}" if @file.nil?
        error "No such file #{tag}" unless File.exists?(File.join(@working_dir, 'fragments', @file))
        replace_fragment 
    end
  end
end

Instance Method Details

#to_htmlObject

Public: Get the page in html format.

Returns the html code of the page as a String.



30
31
32
# File 'lib/genit/documents/fragment.rb', line 30

def to_html
  @page.to_html
end