Sha256: 59461a02b05eeffed8e339514487fef731ee29403316b862b8e96321e54b5d5d
Contents?: true
Size: 1.06 KB
Versions: 6
Compression:
Stored size: 1.06 KB
Contents
# -*- encoding: utf-8 -*- module Genit # Replace each fragment in a page. class Fragment # Public: Constructor. # # file - Full String filename of the page. # working_dir - The String working directory, where live the project. 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'] replace_fragment end end end # Public: Get the page in html format. # # Returns the html code of the page as a String. def to_html @page.to_html end private def replace_fragment builder = Builder.new(@page) @page = builder.replace(css_rule, content) end def css_rule "genit.fragment[file='#{@file}']" end def content full_path = File.join(@working_dir, 'fragments', @file) HtmlDocument.open_as_string(full_path) end end end
Version data entries
6 entries across 6 versions & 1 rubygems