Class: Marker::Template

Inherits:
ParseNode show all
Defined in:
lib/marker/templates.rb

Instance Method Summary collapse

Methods inherited from Treetop::Runtime::SyntaxNode

#present?

Instance Method Details

#arg_list(format, options) ⇒ Object



43
44
45
# File 'lib/marker/templates.rb', line 43

def arg_list( format, options )
  ( args ? args.to_arg_list( format, options ) : [[], {}] )
end

#argsObject

:nodoc:



56
57
58
# File 'lib/marker/templates.rb', line 56

def args #:nodoc:
  nil
end

#block?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/marker/templates.rb', line 47

def block?
  ( args ? args.block? : false )
end

#render(format, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/marker/templates.rb', line 28

def render( format, options = {} )
  # optionally change the format for argument rendering
  if options[:template_formats] and options[:template_formats][target]
    format = options[:template_formats][target]
  end

  ordered, named = arg_list( format, options )
  Marker.templates.send( target, format, ordered, named, options )
end

#tObject

– defaults ++



52
53
54
# File 'lib/marker/templates.rb', line 52

def t #:nodoc:
  nil
end

#targetObject



38
39
40
41
# File 'lib/marker/templates.rb', line 38

def target
  # sanitize the string to get a method name
  t.text_value.downcase.gsub(/\s/, '_').to_sym
end

#to_html(options = {}) ⇒ Object



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

def to_html( options = {} )
  # if this template contains block-style arguments, then it needs to be
  # wrapped in a div.  otherwise, all arguments are inline and it does not
  # get wrapped.  the template target is used as the html class.
  #
  # it may be a good idea to wrap inline templates in a span
  if block?
    "<div class='#{target}'>#{render( :html, options )}</div>"
  else
    render( :html, options )
  end
end

#to_s(options = {}) ⇒ Object



24
25
26
# File 'lib/marker/templates.rb', line 24

def to_s( options = {} )
  render( :text, options )
end