Module: Zafu::Process::RubyLessProcessing

Includes:
RubyLess
Defined in:
lib/zafu/process/ruby_less_processing.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/zafu/process/ruby_less_processing.rb', line 8

def self.included(base)
  base.process_unknown :rubyless_eval

  base.class_eval do
    def do_method(sym)
      super
    rescue RubyLess::Error => err
      parser_error(err.message)
    end
  end
end

Instance Method Details

#append_markup_attr(markup, key, value) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/zafu/process/ruby_less_processing.rb', line 92

def append_markup_attr(markup, key, value)
  value = RubyLess.translate_string(value, self)
  if value.literal
    markup.append_param(key, value.literal)
  else
    markup.append_dyn_param(key, "<%= #{value} %>")
  end
end

#get_attribute_or_eval(use_string_block = true) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/zafu/process/ruby_less_processing.rb', line 101

def get_attribute_or_eval(use_string_block = true)
  if attribute = @params[:attr] || @params[:date]
    code = "this.#{attribute}"
  elsif code = @params[:eval] || @params[:test]
  elsif text = @params[:text]
    code = "%Q{#{text}}"
  elsif use_string_block && @blocks.size == 1 && @blocks.first.kind_of?(String)
    return RubyLess::TypedString.new(@blocks.first.inspect, :class => String, :literal => @blocks.first)
  else
    return parser_continue("Missing attribute/eval parameter")
  end

  RubyLess.translate(code, self)
rescue RubyLess::Error => err
  return parser_continue(err.message, code)
end

#r_erbObject

TEMPORARY METHOD DURING HACKING…



69
70
71
# File 'lib/zafu/process/ruby_less_processing.rb', line 69

def r_erb
  "<pre><%= @erb.gsub('<','&lt;').gsub('>','&gt;') %></pre>"
end

#r_mObject

Print documentation on the current node type.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/zafu/process/ruby_less_processing.rb', line 48

def r_m
  if @params[:helper] == 'true'
    klass = helper.class
  else
    klass = node.klass
  end

  out "<div class='rubyless-m'><h3>Documentation for <b>#{klass}</b></h3>"
  out "<ul>"
  RubyLess::SafeClass.safe_methods_for(klass).each do |signature, opts|
    opts = opts.dup
    opts.delete(:method)
    if opts.keys == [:class]
      opts = opts[:class]
    end
    out "<li>#{signature.inspect} => #{opts.inspect}</li>"
  end
  out "</ul></div>"
end

#rubyless_eval(params = @params) ⇒ Object

Resolve unknown methods by using RubyLess in the current compilation context (the translate method in RubyLess will call ‘safe_method_type’ in this module).



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zafu/process/ruby_less_processing.rb', line 30

def rubyless_eval(params = @params)
  if @method =~ /^[A-Z]\w+$/
    return rubyless_class_scope(@method)
  end

  if code = @method[/^\#\{(.+)\}$/, 1]
    params[:eval] = $1
    r_show
  else
    rubyless_render(@method, params)
  end
rescue RubyLess::NoMethodError => err
  parser_continue("#{err.error_message} <span class='type'>#{err.method_with_arguments}</span> for #{err.receiver_with_class}")
rescue RubyLess::Error => err
  parser_continue(err.message)
end

#rubyless_render(method, params) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/zafu/process/ruby_less_processing.rb', line 73

def rubyless_render(method, params)
  # We need to set this here because we cannot pass options to RubyLess or get them back
  # when we evaluate the method to see if we can use blocks as arguments.
  @rendering_block_owner = true
  code = method_with_arguments(method, params)
  rubyless_expand RubyLess.translate(code, self)
ensure
  @rendering_block_owner = false
end

#safe_method_type(signature) ⇒ Object

Actual method resolution. The lookup first starts in the current helper. If nothing is found there, it searches inside a ‘helpers’ module and finally looks into the current node_context. If nothing is found at this stage, we prepend the method with the current node and start over again.



23
24
25
26
# File 'lib/zafu/process/ruby_less_processing.rb', line 23

def safe_method_type(signature)
  #puts [node.name, node.klass, signature].inspect
  super || get_method_type(signature, false)
end

#set_markup_attr(markup, key, value) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/zafu/process/ruby_less_processing.rb', line 83

def set_markup_attr(markup, key, value)
  value = value.kind_of?(RubyLess::TypedString) ? value : RubyLess.translate_string(value, self)
  if value.literal
    markup.set_param(key, value.literal)
  else
    markup.set_dyn_param(key, "<%= #{value} %>")
  end
end