Class: Deas::Kramdown::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/deas-kramdown/source.rb

Defined Under Namespace

Classes: NullCache

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, opts) ⇒ Source

Returns a new instance of Source.



11
12
13
14
15
# File 'lib/deas-kramdown/source.rb', line 11

def initialize(root, opts)
  @root     = Pathname.new(root.to_s)
  @doc_opts = opts[:doc_opts] || {}
  @cache    = opts[:cache] ? Hash.new : NullCache.new
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



9
10
11
# File 'lib/deas-kramdown/source.rb', line 9

def cache
  @cache
end

#doc_optsObject (readonly)

Returns the value of attribute doc_opts.



9
10
11
# File 'lib/deas-kramdown/source.rb', line 9

def doc_opts
  @doc_opts
end

#rootObject (readonly)

Returns the value of attribute root.



9
10
11
# File 'lib/deas-kramdown/source.rb', line 9

def root
  @root
end

Instance Method Details

#compile(template_name, content) ⇒ Object



21
22
23
# File 'lib/deas-kramdown/source.rb', line 21

def compile(template_name, content)
  doc(content).to_html
end

#doc(content) ⇒ Object



25
26
27
# File 'lib/deas-kramdown/source.rb', line 25

def doc(content)
  Kramdown::Document.new(content, @doc_opts)
end

#inspectObject



29
30
31
32
33
# File 'lib/deas-kramdown/source.rb', line 29

def inspect
  "#<#{self.class}:#{'0x0%x' % (object_id << 1)}"\
  " @root=#{@root.inspect}"\
  " @doc_opts=#{@doc_opts.inspect}>"
end

#render(template_name) ⇒ Object



17
18
19
# File 'lib/deas-kramdown/source.rb', line 17

def render(template_name)
  load(template_name).to_html
end