Class: Liquid::Pry::Tag

Inherits:
Tag
  • Object
show all
Defined in:
lib/liquid/pry/tag.rb

Overview

Interrupts rendering, allowing user to inspect or modify the context.

Examples:

{% pry %}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ Tag

Returns a new instance of Tag.



14
15
16
17
18
# File 'lib/liquid/pry/tag.rb', line 14

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

Instance Attribute Details

#onceObject (readonly)

Returns the value of attribute once.



11
12
13
# File 'lib/liquid/pry/tag.rb', line 11

def once
  @once
end

#visitedObject (readonly)

Returns the value of attribute visited.



12
13
14
# File 'lib/liquid/pry/tag.rb', line 12

def visited
  @visited
end

Instance Method Details

#parse_args(args_str) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/liquid/pry/tag.rb', line 20

def parse_args(args_str)
  case args_str.strip
  when ""
    return
  when "once"
    set_once
  else
    raise(
      ArgumentError,
      "Arguments passed to pry tag could not be recognized: #{args_str}",
    )
  end
end

#render(context) ⇒ Object



38
39
40
41
42
# File 'lib/liquid/pry/tag.rb', line 38

def render(context)
  binding.pry unless once && visited
  @visited = true
  ""
end

#set_onceObject



34
35
36
# File 'lib/liquid/pry/tag.rb', line 34

def set_once
  @once = true
end