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_erb ⇒ Object
TEMPORARY METHOD DURING HACKING…
-
#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
-
#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
97 98 99 100 101 102 103 104 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 97 def append_markup_attr(markup, key, value) value = RubyLess.translate_string(self, value) 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
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 106 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(self, code) rescue RubyLess::Error => err return parser_continue(err., code) end |
#r_erb ⇒ Object
TEMPORARY METHOD DURING HACKING…
64 65 66 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 64 def r_erb "<pre><%= @erb.gsub('<','<').gsub('>','>') %></pre>" end |
#r_m ⇒ Object
Print documentation on the current node type.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 43 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 |
# 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 rubyless_render(@method, params) rescue RubyLess::NoMethodError => err parser_continue("#{err.} <span class='type'>#{err.method_with_arguments}</span> for #{err.receiver_with_class}") rescue RubyLess::Error => err parser_continue(err.) end |
#rubyless_render(method, params) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 68 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. begin @rendering_block_owner = true code = method_with_arguments(method, params) RubyLess.translate(self, code) rescue RubyLess::Error => err if !@params.empty? # try to use r_show without using params as arguments params[:eval] = @method r_show else raise err end ensure @rendering_block_owner = false end 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 26 |
# File 'lib/zafu/process/ruby_less_processing.rb', line 23 def safe_method_type(signature, receiver = nil) #puts [node.name, node.klass, signature].inspect super || get_method_type(signature, false) end |
#set_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 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, value.literal) else markup.set_dyn_param(key, "<%= #{value} %>") end end |