Module: Zafu::Process::RubyLessProcessing
- Includes:
- RubyLess
- Defined in:
- lib/zafu/process/ruby_less_processing.rb
Class Method Summary collapse
Instance Method Summary collapse
- #append_markup_attr(markup, key, value) ⇒ Object
- #get_attribute_or_eval(use_string_block = true) ⇒ Object
-
#r_default ⇒ Object
Pass default values as parameters in @context as :param_XXXX.
-
#r_m ⇒ Object
Print documentation on the current node type.
-
#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).
-
#rubyless_render(method, params) ⇒ Object
TEMPORARY METHOD DURING HACKING…
-
#safe_method_type(signature, receiver = nil) ⇒ Object
Actual method resolution.
- #set_markup_attr(markup, key, value) ⇒ Object
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.) end end end |
Instance Method Details
#append_markup_attr(markup, key, value) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 88 def append_markup_attr(markup, key, value) value = RubyLess.translate_string(self, value) if value.literal markup.append_param(key, form_quote(value.literal)) else markup.append_dyn_param(key, "<%= #{value} %>") end end |
#get_attribute_or_eval(use_string_block = true) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 97 def get_attribute_or_eval(use_string_block = true) if @params[:date] && method != 'link' return parser_continue("'date' parameter is deprecated. Please use 'attr' or 'eval'.") elsif attribute = @params[:attr] code = "this.#{attribute}" elsif code = @params[:eval] || @params[:test] elsif code = @params[:param] code = "params[:#{code}]" elsif text = @params[:text] code = "%Q{#{text}}" elsif text = @params[:t] code = "t(%Q{#{text}})" # elsif var = @params[:var] # if code = get_context_var('set_var', var) # return code # else # return parser_continue("Var #{var.inspect} not declared.") # end 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(self, code) rescue RubyLess::Error => err return parser_continue(err., code) end |
#r_default ⇒ Object
Pass default values as parameters in @context as :param_XXXX
127 128 129 130 131 132 133 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 127 def r_default cont = {} @params.each do |k, v| cont[:"params_#{k}"] = v end cont end |
#r_m ⇒ Object
Print documentation on the current node type.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 42 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).
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 29 def rubyless_eval(params = @params) if @method =~ /^([A-Z]\w+?)\?$/ return rubyless_class_scope($1) end rubyless_render(@method, params) rescue RubyLess::NoMethodError => err parser_continue("#{err.} <span class='type'>#{err.method_with_arguments}</span> (#{node.klass} context)") rescue RubyLess::Error => err parser_continue(err.) end |
#rubyless_render(method, params) ⇒ Object
TEMPORARY METHOD DURING HACKING… def r_erb
"<pre><%= @erb.gsub('<','<').gsub('>','>') %></pre>"
end
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 67 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) # It is strange that we need to freeze code... But if we don't, we # get double ##{} on some systems (Linux). RubyLess.translate(self, code.freeze) ensure @rendering_block_owner = false end |
#safe_method_type(signature, receiver = nil) ⇒ 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 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 23 def safe_method_type(signature, receiver = nil) super || get_method_type(signature, false) end |
#set_markup_attr(markup, key, value) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 79 def set_markup_attr(markup, key, value) value = value.kind_of?(RubyLess::TypedString) ? value : RubyLess.translate_string(self, value) if value.literal markup.set_param(key, form_quote(value.literal)) else markup.set_dyn_param(key, "<%= #{value} %>") end end |