Module: Zena::Use::Urls::ZafuMethods
- Includes:
- RubyLess
- Defined in:
- lib/zena/use/urls.rb
Overview
ViewMethods
Instance Method Summary collapse
-
#insert_dom_id(signature) ⇒ Object
Add the dom_id inside a RubyLess built method (used with make_href and ajax).
-
#make_link(options = {}) ⇒ Object
Create a link tag.
-
#r_anchor ⇒ Object
Insert a named anchor.
-
#r_link ⇒ Object
creates a link.
Instance Method Details
#insert_dom_id(signature) ⇒ Object
Add the dom_id inside a RubyLess built method (used with make_href and ajax).
337 338 339 340 |
# File 'lib/zena/use/urls.rb', line 337 def insert_dom_id(signature) return nil if signature.size != 1 {:method => @insert_dom_id, :class => String} end |
#make_link(options = {}) ⇒ Object
Create a link tag.
Parameters (hash)
-
:update
- DOM_ID: produce an Ajax call that will update this part of the page (optional) -
:default_text
- default text to use for the link if there are no ‘text’, ‘eval’ or ‘attr’ params -
:action
- link action (edit, show, etc)
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/zena/use/urls.rb', line 381 def make_link( = {}) remote_target = ([:update] || @params.delete(:update)) [:action] ||= @params.delete(:action) confirm = @params.delete(:confirm) @markup.tag ||= 'a' if @markup.tag == 'a' markup = @markup else markup = Zafu::Markup.new('a') end steal_and_eval_html_params_for(markup, @params) href = make_href(remote_target, ) # This is to make sure live_id is set *inside* the <a> tag. if @live_param text = add_live_id(text_for_link, markup) @live_param = nil else text = text_for_link([:default_text]) end http_method = http_method_from_action([:action]) if http_method == 'delete' confirm ||= '#{t("Destroy ?")} "#{title}"' end if confirm confirm = ::RubyLess.translate_string(self, confirm) if confirm.literal markup.set_param(:"data-confirm", confirm.literal) else markup.set_dyn_param(:"data-confirm", "<%= #{confirm} %>") end end if remote_target # ajax link (link_to_remote) # Add href to non-ajax method. markup.set_dyn_param(:href, "<%= #{make_href(nil, .merge(:update => false))} %>") # Use onclick with Ajax. markup.set_dyn_param(:onclick, "new Ajax.Request(\"<%= #{href} %>\", {asynchronous:true, evalScripts:true, method:\"#{http_method}\"}); return false;") else markup.set_dyn_param(:href, "<%= #{href} %>") if http_method != 'get' || confirm markup.set_dyn_param(:onclick, "return Zena.m(this,#{http_method.inspect})") end end # We wrap without callbacks (before_wrap, after_wrap) so that the link # is used as raw text in these callbacks. markup.wrap(text) =begin query_params = options[:query_params] || {} default_text = options[:default_text] params = {} (options[:params] || @params).each do |k,v| next if v.nil? params[k] = v end opts = {} if href = params.delete(:href) if lnode = get_context_var('set_var', value) && stored.klass <= Node # using stored node else lnode, klass = build_finder(:first, href, {}) return unless lnode return parser_error("invalid class (#{klass})") unless klass.ancestors.include?(Node) end else # obj if node_class == Version lnode = "#{node}.node" opts[:lang] = "#{node}.lang" elsif node.will_be?(Node) lnode = node else lnode = @context[:previous_node] end end if fmt = params.delete(:format) if fmt == 'data' opts[:format] = "#{node}.ext" else opts[:format] = fmt.inspect end end if mode = params.delete(:mode) opts[:mode] = mode.inspect end if anchor = params.delete(:anchor) opts[:anchor] = anchor.inspect end if anchor_in = params.delete(:in) finder, klass = build_finder(:first, anchor_in, {}) return unless finder return parser_error("invalid class (#{klass})") unless klass.ancestors.include?(Node) opts[:anchor_in] = finder end if @html_tag && @html_tag != 'a' # FIXME: can we remove this ? # html attributes do not belong to anchor pre_space = '' html_params = {} else html_params = get_html_params(params.merge(@html_tag_params), :link) pre_space = @space_before || '' @html_tag_done = true end (params.keys - [:style, :class, :id, :rel, :name, :anchor, :attr, :tattr, :trans, :text]).each do |k| next if k.to_s =~ /if_|set_|\A_/ query_params[k] = params[k] end # TODO: merge these two query_params cleanup things into something cleaner. else # direct link query_params.each do |k,v| if k == :date if v == 'current_date' query_params[k] = current_date elsif v =~ /\A\d/ query_params[k] = v.inspect elsif v =~ /\[/ attribute, static = parse_attributes_in_value(v.gsub('"',''), :erb => false) query_params[k] = "\"#{attribute}\"" else query_params[k] = node_attribute(v) end else attribute, static = parse_attributes_in_value(v.gsub('"',''), :erb => false) query_params[k] = "\"#{attribute}\"" end end query_params.merge!(opts) opts_str = '' query_params.keys.sort {|a,b| a.to_s <=> b.to_s }.each do |k| opts_str << ",:#{k.to_s.gsub(/[^a-z_A-Z_]/,'')}=>#{query_params[k]}" end pre_space + "<a#{params_to_html(html_params)} href='<%= zen_path(#{lnode}#{opts_str}) %>'>#{text_for_link(default_text)}</a>" end =end end |
#r_anchor ⇒ Object
Insert a named anchor
368 369 370 371 |
# File 'lib/zena/use/urls.rb', line 368 def r_anchor @params[:anchor] ||= 'true' r_link end |
#r_link ⇒ Object
creates a link. Options are: :href (node, parent, project, root) :tattr (translated attribute used as text link) :attr (attribute used as text link) <r:link href=‘node’><r:trans attr=‘lang’/></r:link> <r:link href=‘node’ tattr=‘lang’/> <r:link update=‘dom_id’/> <r:link page=‘next’/> <r:link page=‘previous’/> <r:link page=‘list’/>
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/zena/use/urls.rb', line 350 def r_link # If we have a contextual timezone set, pass it to @params if tz_name = @params[:tz] tz_result, tz_var = set_tz_var(tz_name) return tz_result unless tz_var @params[:tz] = 'tz' elsif tz_var = get_context_var('set_var', 'tz') @params[:tz] = 'tz' end if @params[:page] && @params[:page] != '[page_page]' # lets users use 'page' as pagination key pagination_links else make_link end end |