Class: ExternalJSON::ExternalJSON_tag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/externaljson.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ ExternalJSON_tag

Returns a new instance of ExternalJSON_tag.



7
8
9
10
# File 'lib/externaljson.rb', line 7

def initialize(tag_name, text, tokens)
  super
  @text = text
end

Instance Method Details

#render(context) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/externaljson.rb', line 12

def render(context)
  if /(.+) from url (.+)/.match(@text)
    resp = Net::HTTP.get_response(URI($2.strip))
    data = resp.body
    context[$1] = JSON data
    nil
  else
    # syntax error
    raise ArgumentError, 'ERROR:bad_syntax'
  end

end