Module: Zena::Use::Action::ZafuMethods

Includes:
Common
Defined in:
lib/zena/use/action.rb

Overview

ViewMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#node_action_link, #win_id

Class Method Details

.included(base) ⇒ Object



178
179
180
# File 'lib/zena/use/action.rb', line 178

def self.included(base)
  base.before_process :filter_actions
end

Instance Method Details

#filter_actionsObject



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/zena/use/action.rb', line 253

def filter_actions
  if actions = @params.delete(:actions)
    node = self.node
    if node.will_be? Node
    elsif node.will_be? Version
      node = "#{node}.node"
    else
      out parser_error("Invalid option 'actions' for #{node.klass}.")
      return
    end

    if publish = @params.delete(:publish)
      out_post " <%= node_actions(#{node}, :actions => #{actions.inspect}, :publish => #{publish.inspect}) %>"
    else
      out_post " <%= node_actions(#{node}, :actions => #{actions.inspect}) %>"
    end
  end
end

#r_actionObject



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/zena/use/action.rb', line 234

def r_action
  return parser_error("Missing 'select' parameter.") unless action = @params[:select]

  if self.node.will_be? Node
    node = self.node
  elsif self.node.will_be? Version
    node = "#{self.node}.node"
  else
    return parser_error("Invalid option 'actions' for #{node.klass}.")
  end

  params = {}
  @params.each do |k,v|
    next if k == :select
    params[k] = RubyLess.translate_string(self, v)
  end
  out node_action_link(action, "<%= #{node}.zip %>", :text => text_for_link(''), :params => params)
end

#r_debugObject Also known as: r_d



182
183
184
185
186
187
188
# File 'lib/zena/use/action.rb', line 182

def r_debug
  %Q{
<pre style='background:white; color:black; border:1px solid red; display:table;'>
class #{node.klass}: #{Array(node.klass).first.columns.keys.join(', ')}
</pre>
  }
end


192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/zena/use/action.rb', line 192

def 
  if dynamic_blocks?
    @markup.tag ||= 'a'
    markup = @markup.tag == 'a' ? @markup : Zafu::Markup.new('a')

    else_markup = markup.dup
    else_markup.set_dyn_param('href', '<%= logout_path %>')

    markup.set_dyn_param('href', '<%= login_path %>')
    unless markup.params[:rel]
      markup.set_param(:rel, 'nofollow')
    end

    out markup.wrap(expand_if("visitor.is_anon?", self.node, else_markup))
  else
    out "<% if visitor.is_anon? %>"
    out "<%= link_to #{_('login').inspect}, login_path, :rel => 'nofollow' %>"
    out "<% else %>"
    out "<%= link_to #{_('logout').inspect}, logout_path %>"
    out "<% end %>"
  end
end

#r_swapObject

TODO: test



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/zena/use/action.rb', line 277

def r_swap
  if upd = @params.delete(:update)
    if upd == '_page'
      block = '_page'
    elsif block = find_target(upd)
      # ok
      if ancestor('block') || ancestor('each')
        # FIXME: not used
        upd_both = '&upd_both=true'
      else
        upd_both = ''
      end
    else
      return
    end
  elsif block = (ancestor('block') || ancestor('each'))
    # ancestor: ok
  elsif parent && block = parent.descendant('block')
    # sibling: ok
    upd_both = ''
  else
    return parser_error("missing 'block' in same parent")
  end

  return parser_error("missing 'states' parameter") unless @params[:states]

  # This will be RubyLess evaluated
  query_params = @params.merge("node[#{@params[:attr]}]" => "next_in_list(this.#{@params[:attr]}, %Q{#{@params[:states]}})")
  query_params.delete(:states)
  query_params.delete(:attr)
  out make_link(:update => block, :action => 'update', :query_params => query_params, :method => :put)
end

#r_versions_listObject



272
273
274
# File 'lib/zena/use/action.rb', line 272

def r_versions_list
  out "<%= render :partial=>'versions/list' %>"
end


215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/zena/use/action.rb', line 215

def r_visitor_link
  out "<% if !visitor.is_anon? %>"
  if dynamic_blocks?
    @markup.tag ||= 'a'
    link = '<%= user_path(visitor) %>'
    if @markup.tag == 'a'
      @markup.set_dyn_param(:href, link)
      out wrap(expand_with)
    else
      markup = Zafu::Markup.new('a')
      markup.set_dyn_param(:href, link)
      out wrap(markup.wrap(expand_with))
    end
  else
    out wrap("<%= link_to visitor.node.title, user_path(visitor) %>")
  end
  out "<% end %>"
end