Module: Roda::RodaPlugins::Phlex::InstanceMethods
- Defined in:
- lib/roda/plugins/phlex.rb
Instance Method Summary collapse
-
#phlex(obj, content_type: nil, stream: false) ⇒ Object
Renders a Phlex object.
-
#phlex_layout(layout = Undefined) ⇒ Phlex::SGML?
Retrieves or sets the layout.
-
#phlex_layout_handler(handler = Undefined) ⇒ #call?
Retrieves or sets the layout handler.
-
#phlex_layout_opts(layout_opts = Undefined) ⇒ Object?
Retrieves or sets the layout options.
Instance Method Details
#phlex(obj, content_type: nil, stream: false) ⇒ Object
Renders a Phlex object.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/roda/plugins/phlex.rb', line 144 def phlex(obj, content_type: nil, stream: false) raise TypeError.new(obj) unless obj.is_a?(::Phlex::SGML) content_type ||= "image/svg+xml" if obj.is_a?(::Phlex::SVG) response["Content-Type"] = content_type if content_type phlex_opts = opts[:phlex] renderer = if (layout = phlex_opts[:layout]) phlex_layout_handler.call(layout, phlex_opts[:layout_opts], obj) else obj end if stream self.stream do |out| renderer.call(out, view_context: self) end else renderer.call(view_context: self) end end |
#phlex_layout(layout = Undefined) ⇒ Phlex::SGML?
Retrieves or sets the layout.
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/roda/plugins/phlex.rb', line 98 def phlex_layout(layout = Undefined) case layout when Undefined opts.dig(:phlex, :layout) when nil opts[:phlex].delete(:layout) opts[:phlex].delete(:layout_opts) when ::Phlex::SGML opts[:phlex][:layout] = layout else raise TypeError.new(layout) end end |
#phlex_layout_handler(handler = Undefined) ⇒ #call?
Retrieves or sets the layout handler.
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/roda/plugins/phlex.rb', line 129 def phlex_layout_handler(handler = Undefined) case handler when Undefined opts.dig(:phlex, :layout_handler) when nil opts[:phlex].delete(:layout_handler) else opts[:phlex][:layout_handler] = handler end end |
#phlex_layout_opts(layout_opts = Undefined) ⇒ Object?
Retrieves or sets the layout options.
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/roda/plugins/phlex.rb', line 115 def phlex_layout_opts(layout_opts = Undefined) case layout_opts when Undefined opts.dig(:phlex, :layout_opts) when nil opts[:phlex].delete(:layout_opts) else opts[:phlex][:layout_opts] = layout_opts end end |