Module: Card::Format::Render
- Included in:
- Card::Format
- Defined in:
- lib/card/format/render.rb
Overview
View rendering methods.
Instance Method Summary collapse
- #add_debug_info(view, method, rendered) ⇒ Object
- #api_render(match, opts) ⇒ Object
- #current_view(view) ⇒ Object
- #expand_stubs(cached_content) ⇒ Object
- #final_render(view, args) ⇒ Object
- #optional_render_args(args, opts) ⇒ Object
- #prepare_stub_nest(stub_hash) {|stub_card, , stub_options| ... } ⇒ Object
- #pretty_path(source_location) ⇒ Object
- #render(view, args = {}) ⇒ Object
- #show_debug_info? ⇒ Boolean
- #show_view?(view, default_viz = :show) ⇒ Boolean
- #stub_render(cached_content) ⇒ Object
-
#view_cache_setting(view) ⇒ Object
setting (:alway, :never, :nested) designated in view definition.
- #view_method(view) ⇒ Object
- #view_options_with_defaults(view, options) ⇒ Object
- #voo ⇒ Object
- #with_voo(voo) ⇒ Object
Instance Method Details
#add_debug_info(view, method, rendered) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/card/format/render.rb', line 51 def add_debug_info view, method, rendered return rendered unless show_debug_info? <<-HTML <view-debug view='#{card.name}##{view}' src='#{pretty_path method.source_location}' module='#{method.owner}'/> #{rendered} HTML end |
#api_render(match, opts) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/card/format/render.rb', line 103 def api_render match, opts view = match[3] ? match[4] : opts.shift args = opts[0] ? opts.shift.clone : {} optional_render_args(args, opts) if match[2] args[:skip_perms] = true if match[1] render view, args end |
#current_view(view) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/card/format/render.rb', line 122 def current_view view old_view = @current_view @current_view = view yield ensure @current_view = old_view end |
#expand_stubs(cached_content) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/card/format/render.rb', line 95 def cached_content conto = Card::Content.new cached_content, self, chunk_list: :stub conto.process_each_chunk do |stub_hash| yield(stub_hash).to_s end conto.to_s end |
#final_render(view, args) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/card/format/render.rb', line 41 def final_render view, args current_view(view) do with_nest_mode view do method = view_method view rendered = method.arity.zero? ? method.call : method.call(args) add_debug_info view, method, rendered end end end |
#optional_render_args(args, opts) ⇒ Object
111 112 113 |
# File 'lib/card/format/render.rb', line 111 def optional_render_args args, opts args[:optional] = opts.shift || :show end |
#prepare_stub_nest(stub_hash) {|stub_card, , stub_options| ... } ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/card/format/render.rb', line 86 def prepare_stub_nest stub_hash stub_card = Card.fetch_from_cast stub_hash[:cast] = stub_hash[:options] if stub_card.key.present? && stub_card.key == card.key [:nest_name] ||= "_self" end yield stub_card, stub_hash[:mode], end |
#pretty_path(source_location) ⇒ Object
63 64 65 66 |
# File 'lib/card/format/render.rb', line 63 def pretty_path source_location source_location.first.gsub(%r{^.+mod\d+-([^/]+)}, '\1: ') + ':' + source_location.second.to_s end |
#render(view, args = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/card/format/render.rb', line 6 def render view, args={} voo = View.new self, view, args, @voo with_voo voo do voo.process do |final_view, | final_render final_view, end end rescue => e rescue_view e, view end |
#show_debug_info? ⇒ Boolean
59 60 61 |
# File 'lib/card/format/render.rb', line 59 def show_debug_info? Env.params[:debug] == "view" end |
#show_view?(view, default_viz = :show) ⇒ Boolean
35 36 37 38 39 |
# File 'lib/card/format/render.rb', line 35 def show_view? view, default_viz=:show voo. # trigger viz processing visibility = voo.viz_hash[view] || default_viz visibility == :show end |
#stub_render(cached_content) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/card/format/render.rb', line 77 def stub_render cached_content return cached_content unless cached_content.is_a? String cached_content do |stub_hash| prepare_stub_nest(stub_hash) do |stub_card, mode, | with_nest_mode(mode) { nest stub_card, } end end end |
#view_cache_setting(view) ⇒ Object
setting (:alway, :never, :nested) designated in view definition
69 70 71 72 73 74 75 |
# File 'lib/card/format/render.rb', line 69 def view_cache_setting view method = self.class.view_cache_setting_method view coded_setting = respond_to?(method) ? send(method) : :standard return :never if coded_setting == :never # seems unwise to override a hard-coded "never" (voo && voo.cache) || coded_setting end |
#view_method(view) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/card/format/render.rb', line 115 def view_method view method "_view_#{view}" rescue voo.unsupported_view = view method "_view_unsupported_view" end |
#view_options_with_defaults(view, options) ⇒ Object
25 26 27 28 29 |
# File 'lib/card/format/render.rb', line 25 def view, default_method = "default_#{view}_args" send default_method, if respond_to? default_method end |
#voo ⇒ Object
31 32 33 |
# File 'lib/card/format/render.rb', line 31 def voo @voo end |
#with_voo(voo) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/card/format/render.rb', line 17 def with_voo voo old_voo = @voo @voo = voo result = yield @voo = old_voo result end |