Module: Zena::Use::Action::ZafuMethods
- Includes:
- Common
- Defined in:
- lib/zena/use/action.rb
Overview
ViewMethods
Class Method Summary collapse
Instance Method Summary collapse
- #filter_actions ⇒ Object
- #r_action ⇒ Object
- #r_debug ⇒ Object (also: #r_d)
- #r_login_link ⇒ Object
-
#r_swap ⇒ Object
TODO: test.
- #r_visitor_link ⇒ Object
Methods included from Common
Class Method Details
.included(base) ⇒ Object
172 173 174 |
# File 'lib/zena/use/action.rb', line 172 def self.included(base) base.before_process :filter_actions end |
Instance Method Details
#filter_actions ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/zena/use/action.rb', line 239 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_action ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/zena/use/action.rb', line 225 def r_action return parser_error("Missing 'action' 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 out node_action_link(action, "<%= #{node}.zip %>", :text => text_for_link(''), :publish => @params[:publish]) end |
#r_debug ⇒ Object Also known as: r_d
176 177 178 179 180 181 182 |
# File 'lib/zena/use/action.rb', line 176 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 |
#r_login_link ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/zena/use/action.rb', line 186 def r_login_link 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 %>') out markup.wrap(("visitor.is_anon?", self.node, else_markup)) else out "<% if visitor.is_anon? %>" out "<%= link_to #{_('login').inspect}, login_path %>" out "<% else %>" out "<%= link_to #{_('logout').inspect}, logout_path %>" out "<% end %>" end end |
#r_swap ⇒ Object
TODO: test
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/zena/use/action.rb', line 260 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_visitor_link ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/zena/use/action.rb', line 206 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() else markup = Zafu::Markup.new('a') markup.set_dyn_param(:href, link) out wrap(markup.wrap()) end else out wrap("<%= link_to visitor.node.title, user_path(visitor) %>") end out "<% end %>" end |