Class: Cadmus::Tags::PageUrl

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, args, tokens) ⇒ PageUrl

Returns a new instance of PageUrl.



14
15
16
17
# File 'lib/cadmus/tags.rb', line 14

def initialize(tag_name, args, tokens)
  super
  @page_name = args.strip
end

Class Attribute Details

.page_path_methodObject (readonly)

Returns the value of attribute page_path_method.



5
6
7
# File 'lib/cadmus/tags.rb', line 5

def page_path_method
  @page_path_method
end

Instance Attribute Details

#page_nameObject (readonly)

Returns the value of attribute page_name.



12
13
14
# File 'lib/cadmus/tags.rb', line 12

def page_name
  @page_name
end

Class Method Details

.define_page_path_method(&page_path_method) ⇒ Object



7
8
9
# File 'lib/cadmus/tags.rb', line 7

def define_page_path_method(&page_path_method)
  @page_path_method = page_path_method
end

Instance Method Details

#render(context) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cadmus/tags.rb', line 19

def render(context)
  unless self.class.page_path_method
    return "Error: #{self.class.name}.page_path_method is not defined.  Please call #{self.class.name}.define_page_path_method in an initializer."
  end

  begin
    parent = context.registers['parent']
    Rails.application.routes.url_helpers.instance_exec(page_name, parent, &self.class.page_path_method)
  rescue Exception => e
    e.message
  end
end