Module: Zena::Use::Context::ZafuMethods
- Includes:
- RubyLess
- Defined in:
- lib/zena/use/context.rb
Overview
ViewMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#node(klass = nil) ⇒ Object
Return the node context for a given class (looks up into the hierarchy) or the current node context if klass is nil.
-
#r_context ⇒ Object
(also: #r_find)
Enter a new context (<r:context find=‘all’ select=‘pages’>).
- #r_count ⇒ Object
- #r_dom_id ⇒ Object
- #r_each_group ⇒ Object
-
#r_group ⇒ Object
Group elements in a list.
- #r_set ⇒ Object
Class Method Details
.dom_id_proc ⇒ Object
146 147 148 149 150 |
# File 'lib/zena/use/context.rb', line 146 def self.dom_id_proc Proc.new do |h, r, s| {:class => String, :method => h.node.dom_id(:code => true)} end end |
Instance Method Details
#node(klass = nil) ⇒ Object
Return the node context for a given class (looks up into the hierarchy) or the current node context if klass is nil.
164 165 166 |
# File 'lib/zena/use/context.rb', line 164 def node(klass = nil) super(klass && klass.kind_of?(VirtualClass) ? klass.real_class : klass) end |
#r_context ⇒ Object Also known as: r_find
Enter a new context (<r:context find=‘all’ select=‘pages’>). This is the same as ‘<r:pages>…</r:pages>’). It is considered better style to use ‘<r:pages>…</r:pages>’ instead of the more general ‘<r:context>’ because the tags give a clue on the context at start and end. Another way to open a context is the ‘do’ syntax: “<div do=‘pages’>…</div>”.
171 172 173 174 |
# File 'lib/zena/use/context.rb', line 171 def r_context return parser_error("missing 'select' parameter") unless method = @params[:select] querybuilder_eval(method) end |
#r_count ⇒ Object
178 179 180 181 182 183 184 185 |
# File 'lib/zena/use/context.rb', line 178 def r_count if node.list_context? && !@params[:select] rubyless_eval else @params[:find] = 'count' r_context end end |
#r_dom_id ⇒ Object
156 157 158 |
# File 'lib/zena/use/context.rb', line 156 def r_dom_id out node.dom_id end |
#r_each_group ⇒ Object
255 256 257 |
# File 'lib/zena/use/context.rb', line 255 def r_each_group r_each end |
#r_group ⇒ Object
Group elements in a list. Use :order to specify order.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/zena/use/context.rb', line 208 def r_group return parser_error("cannot be used outside of a list") unless node.list_context? return parser_error("missing 'by' clause") unless key = @params[:by] #sort_key = @params[:sort] || 'title' # if node.will_be?(DataEntry) && DataEntry::NodeLinkSymbols.include?(key.to_sym) # key = "#{key}_id" # #sort_block = "{|e| (e.#{key} || {})[#{sort_key.to_sym.inspect}]}" # group_array = "group_array(#{node}) {|e| e.#{key}}" # elsif node.will_be?(Node) # if ['project', 'parent', 'section'].include?(key) # #sort_block = "{|e| (e.#{key} || {})[#{sort_key.to_sym.inspect}]}" # group_array = "group_array(#{node}) {|e| e.#{key}_id}" # end # end if %w{parent project section}.include?(key) key = "e.#{key}_id" else receiver = RubyLess::TypedString.new('e', :class => node.klass.first, :query => node.opts[:query]) key = RubyLess.translate(receiver, key) end #if sort_block # out "<% grp_#{list_var} = sort_array(#{group_array}) #{sort_block} %>" #else #end method = "group_array(#{node}) {|e| #{key}}" out "<% if #{var} = #{method} %>" open_node_context({:method => method}, :node => node.move_to(var, [node.klass], :query => node.opts[:query])) do if child['each_group'] out else @var = nil r_each end end out "<% end %>" #if descendant('each_group') # out expand_with(:group => var) #else # @context[:group] = var # r_each_group #end end |
#r_set ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/zena/use/context.rb', line 187 def r_set @params.each do |var, code| var = var.to_s begin typed_string = ::RubyLess.translate(self, code) name = get_var_name('set_var', var) out "<% #{name} = #{typed_string} %>" var_setting = {} set_context_var('set_var', var, RubyLess::TypedString.new(name, typed_string.opts), var_setting) # Leak into following siblings self.pass(var_setting) # Set inside @context.merge!(var_setting) rescue RubyLess::NoMethodError => err parser_error(err., code) end end end |