Class: Jekyll::Geolexica::JbuilderTag::JbuilderWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/geolexica/jbuilder_tag.rb

Overview

Instance of this class becomes self in Jbuilder templates. It provides access to Jbuilder instance and current Jekyll context via json and context accessors, respectively. There are convenient accessors to site and page Jekyll context variables, too.

Examples:

# Should render {"time": "<time when site was generated>"}
json.now context["site"]["time"]
# Alternatively
json.now site["time"]

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ JbuilderWrapper

Returns a new instance of JbuilderWrapper.



33
34
35
36
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 33

def initialize(context)
  @builder = Jbuilder.new
  @context = context
end

Instance Method Details

#contextObject



42
43
44
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 42

def context
  @context
end

#eval_source(source) ⇒ Object



54
55
56
57
58
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 54

def eval_source(source)
  instance_eval(source)
rescue
  raise Error.new(source)
end

#jsonObject



38
39
40
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 38

def json
  @builder
end

#pageObject



46
47
48
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 46

def page
  @context["page"]
end

#siteObject



50
51
52
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 50

def site
  @context["site"]
end

#target!Object

This generates pretty output contrary to Jbuilder#target!.



61
62
63
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 61

def target!
  JSON.pretty_generate(@builder.attributes!)
end