Class: Ecstatic::Page
- Inherits:
-
Object
- Object
- Ecstatic::Page
- Defined in:
- lib/ecstatic.rb
Instance Attribute Summary collapse
-
#contexthash ⇒ Object
Returns the value of attribute contexthash.
-
#layoutfile ⇒ Object
Returns the value of attribute layoutfile.
-
#templatefile ⇒ Object
Returns the value of attribute templatefile.
Instance Method Summary collapse
- #escapefun(format) ⇒ Object
-
#initialize(templatefile = nil, datafiles = [], layoutfile = nil) ⇒ Page
constructor
A new instance of Page.
- #to_format(format) ⇒ Object
- #to_html ⇒ Object
- #to_latex ⇒ Object
- #to_plain ⇒ Object
Constructor Details
#initialize(templatefile = nil, datafiles = [], layoutfile = nil) ⇒ Page
Returns a new instance of Page.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ecstatic.rb', line 12 def initialize(templatefile = nil, datafiles = [], layoutfile = nil) @templatefile = templatefile @layoutfile = layoutfile # get context from data files @contexthash = {} datafiles.each do |file| yamltext = File.open(file).read yaml = YAML::load(yamltext) # if YAML is not a hash, make a hash with file's basename as key: unless yaml.class == Hash yaml = {File.basename(file, File.extname(file)) => yaml} end yaml.each_pair do |key,val| model = key.singularize.capitalize begin @contexthash[key] = Object.const_get(model).from_array(val) rescue $stderr.puts("Unable to initialize " + key + " from model " + model) @contexthash[key] = val end end end end |
Instance Attribute Details
#contexthash ⇒ Object
Returns the value of attribute contexthash.
10 11 12 |
# File 'lib/ecstatic.rb', line 10 def contexthash @contexthash end |
#layoutfile ⇒ Object
Returns the value of attribute layoutfile.
10 11 12 |
# File 'lib/ecstatic.rb', line 10 def layoutfile @layoutfile end |
#templatefile ⇒ Object
Returns the value of attribute templatefile.
10 11 12 |
# File 'lib/ecstatic.rb', line 10 def templatefile @templatefile end |
Instance Method Details
#escapefun(format) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ecstatic.rb', line 36 def escapefun(format) case when format == :html return 'Ecstatic.markdown_to_compact_html' when format == :latex return 'Ecstatic.markdown_to_latex' else return 'escape' end end |
#to_format(format) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ecstatic.rb', line 47 def to_format(format) engine = Tenjin::Engine.new(:cache => false, :escapefunc => escapefun(format)) if File.extname(self.templatefile) == '.markdown' contents = File.open(self.templatefile).read output = case when format == :html markdown_to_compact_html(contents) when format == :latex markdown_to_latex(contents) else escape(contents) end else context = Tenjin::Context.new(self.contexthash) output = engine.render(self.templatefile, context) end if self.layoutfile supercontext = Tenjin::Context.new({'_contents' => output}) superoutput = engine.render(self.layoutfile, {'_contents' => output}) return superoutput else return output end end |
#to_html ⇒ Object
74 75 76 |
# File 'lib/ecstatic.rb', line 74 def to_html self.to_format(:html) end |
#to_latex ⇒ Object
78 79 80 |
# File 'lib/ecstatic.rb', line 78 def to_latex self.to_format(:latex) end |
#to_plain ⇒ Object
82 83 84 |
# File 'lib/ecstatic.rb', line 82 def to_plain self.to_format(:plain) end |