Module: Upmin::Railties::RenderHelpers
- Defined in:
- lib/upmin/railties/render_helpers.rb
Class Method Summary collapse
- .action_options(action, options = {}) ⇒ Object
- .action_partials(action, options = {}) ⇒ Object
- .association_options(association, options = {}) ⇒ Object
-
.association_partials(association, options = {}) ⇒ Object
NOTE: assoc_type is sketchy at best.
- .attribute_options(attribute, options = {}) ⇒ Object
- .attribute_partials(attribute, options = {}) ⇒ Object
- .build_action_path(partial) ⇒ Object
- .build_association_path(partial) ⇒ Object
- .build_attribute_path(partial) ⇒ Object
- .build_model_path(partial, prefix = "") ⇒ Object
- .build_parameter_path(partial) ⇒ Object
- .build_path(folder, partial) ⇒ Object
- .build_search_box_path(partial) ⇒ Object
- .build_search_results_path(partial) ⇒ Object
- .model_options(model, options = {}) ⇒ Object
- .model_partials(model, options = {}) ⇒ Object
- .parameter_options(parameter, options = {}) ⇒ Object
- .parameter_partials(parameter, options = {}) ⇒ Object
- .root_path ⇒ Object
- .search_box_options(klass, options = {}) ⇒ Object
- .search_box_partials(klass, options = {}) ⇒ Object
- .search_results_options(query, options = {}) ⇒ Object
- .search_results_partials(query, options = {}) ⇒ Object
Class Method Details
.action_options(action, options = {}) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/upmin/railties/render_helpers.rb', line 112 def RenderHelpers.(action, = {}) [:locals] ||= {} [:locals][:model] ||= action.model [:locals][:action] = action return end |
.action_partials(action, options = {}) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/upmin/railties/render_helpers.rb', line 97 def RenderHelpers.action_partials(action, = {}) partials = [] # <options[:as]> # <model_name>_<action_name>, eg: order_refund # <action_name>, eg: refund # action model_name = action.model.underscore_name partials << build_action_path([:as]) if [:as] partials << build_action_path("#{model_name}_#{action.name}") partials << build_action_path(action.name) partials << build_action_path(:action) return partials end |
.association_options(association, options = {}) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/upmin/railties/render_helpers.rb', line 84 def RenderHelpers.(association, = {}) [:locals] ||= {} [:locals][:model] ||= association.model [:locals][:association] = association return end |
.association_partials(association, options = {}) ⇒ Object
NOTE: assoc_type is sketchy at best. It tries to determine it, but in some cases it has to be guessed at, so if you have polymorphic associations it will choose the data type of the first association it finds - eg if user.things returns [Order, Product, Review] it will use the type of “order”
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/upmin/railties/render_helpers.rb', line 65 def RenderHelpers.association_partials(association, = {}) partials = [] # <options[:as]> # <model_name>_<assoc_name>, eg: user_recent_orders # <model_name>_<assoc_type>, eg: user_orders # <attr_type>, eg: orders # associations model_name = association.model.underscore_name assoc_type = association.type partials << build_association_path([:as]) if [:as] partials << build_association_path("#{model_name}_#{association.name}") partials << build_association_path("#{model_name}_#{assoc_type}") partials << build_association_path(association.name) partials << build_association_path(assoc_type) partials << build_association_path(:associations) return partials end |
.attribute_options(attribute, options = {}) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/upmin/railties/render_helpers.rb', line 51 def RenderHelpers.(attribute, = {}) [:locals] ||= {} [:locals][:model] ||= attribute.model [:locals][:attribute] = attribute return end |
.attribute_partials(attribute, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/upmin/railties/render_helpers.rb', line 31 def RenderHelpers.attribute_partials(attribute, = {}) partials = [] # <options[:as]> # <model_name>_<attr_name>, eg: user_name # <model_name>_<attr_type>, eg: user_string # <attr_type>, eg: string # unknown model_name = attribute.model.underscore_name attr_type = attribute.type partials << build_attribute_path([:as]) if [:as] partials << build_attribute_path("#{model_name}_#{attribute.name}") partials << build_attribute_path("#{model_name}_#{attr_type}") partials << build_attribute_path(attribute.name) partials << build_attribute_path(attr_type) partials << build_attribute_path(:unknown) return partials end |
.build_action_path(partial) ⇒ Object
119 120 121 |
# File 'lib/upmin/railties/render_helpers.rb', line 119 def RenderHelpers.build_action_path(partial) return build_path("actions", partial) end |
.build_association_path(partial) ⇒ Object
91 92 93 |
# File 'lib/upmin/railties/render_helpers.rb', line 91 def RenderHelpers.build_association_path(partial) return build_path("associations", partial) end |
.build_attribute_path(partial) ⇒ Object
58 59 60 |
# File 'lib/upmin/railties/render_helpers.rb', line 58 def RenderHelpers.build_attribute_path(partial) return build_path("attributes", partial) end |
.build_model_path(partial, prefix = "") ⇒ Object
25 26 27 |
# File 'lib/upmin/railties/render_helpers.rb', line 25 def RenderHelpers.build_model_path(partial, prefix = "") return build_path("models", "#{prefix}#{partial}") end |
.build_parameter_path(partial) ⇒ Object
151 152 153 |
# File 'lib/upmin/railties/render_helpers.rb', line 151 def RenderHelpers.build_parameter_path(partial) return build_path("parameters", partial) end |
.build_path(folder, partial) ⇒ Object
207 208 209 210 |
# File 'lib/upmin/railties/render_helpers.rb', line 207 def RenderHelpers.build_path(folder, partial) partial = partial.to_s.gsub(/[!?]/, "") "#{root_path}/#{folder}/#{partial}" end |
.build_search_box_path(partial) ⇒ Object
201 202 203 |
# File 'lib/upmin/railties/render_helpers.rb', line 201 def RenderHelpers.build_search_box_path(partial) return build_path("search_boxes", partial) end |
.build_search_results_path(partial) ⇒ Object
176 177 178 |
# File 'lib/upmin/railties/render_helpers.rb', line 176 def RenderHelpers.build_search_results_path(partial) return build_path("search_results", partial) end |
.model_options(model, options = {}) ⇒ Object
19 20 21 22 23 |
# File 'lib/upmin/railties/render_helpers.rb', line 19 def RenderHelpers.(model, = {}) [:locals] ||= {} [:locals][:model] ||= model return end |
.model_partials(model, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/upmin/railties/render_helpers.rb', line 5 def RenderHelpers.model_partials(model, = {}) partials = [] # Add "new_" in front of any partial for the partial for new view. # <options[:as]> # <model_name> # model prefix = model.new_record? ? "new_" : "" partials << build_model_path([:as]) if [:as] partials << build_model_path(model.underscore_name, prefix) partials << build_model_path(:model, prefix) return partials end |
.parameter_options(parameter, options = {}) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/upmin/railties/render_helpers.rb', line 143 def RenderHelpers.(parameter, = {}) [:locals] ||= {} [:locals][:model] ||= parameter.model [:locals][:action] ||= parameter.action [:locals][:parameter] = parameter return end |
.parameter_partials(parameter, options = {}) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/upmin/railties/render_helpers.rb', line 125 def RenderHelpers.parameter_partials(parameter, = {}) partials = [] # <options[:as]> # <model_name>_<action_name>_<param_name>, eg: order_refund_amount # <action_name>_<param_name>, eg: refund_amount # <param_name>, eg: amount # <param_type>_parameter, eg: opt_parameter and req_parameter model_name = parameter.model.underscore_name action_name = parameter.action.name partials << build_parameter_path([:as]) if [:as] partials << build_parameter_path("#{model_name}_#{action_name}_#{parameter.name}") partials << build_parameter_path("#{action_name}_#{parameter.name}") partials << build_parameter_path(parameter.name) partials << build_parameter_path("#{parameter.type}_parameter") return partials end |
.root_path ⇒ Object
212 213 214 |
# File 'lib/upmin/railties/render_helpers.rb', line 212 def RenderHelpers.root_path return "upmin/partials" end |
.search_box_options(klass, options = {}) ⇒ Object
195 196 197 198 199 |
# File 'lib/upmin/railties/render_helpers.rb', line 195 def RenderHelpers.(klass, = {}) [:locals] ||= {} [:locals][:klass] = klass return end |
.search_box_partials(klass, options = {}) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/upmin/railties/render_helpers.rb', line 182 def RenderHelpers.search_box_partials(klass, = {}) partials = [] # <options[:as]> # <model_name>_search_box, eg: order_search_box # ransack_search_box model_name = klass.underscore_name partials << build_search_box_path([:as]) if [:as] partials << build_search_box_path("#{model_name}_search_box") partials << build_search_box_path(:ransack_search_box) return partials end |
.search_results_options(query, options = {}) ⇒ Object
170 171 172 173 174 |
# File 'lib/upmin/railties/render_helpers.rb', line 170 def RenderHelpers.(query, = {}) [:locals] ||= {} [:locals][:query] = query return end |
.search_results_partials(query, options = {}) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/upmin/railties/render_helpers.rb', line 157 def RenderHelpers.search_results_partials(query, = {}) partials = [] # <options[:as]> # <model_name # plural>, eg: orders # results model_name_plural = query.underscore_name(:plural) partials << build_search_results_path([:as]) if [:as] partials << build_search_results_path(model_name_plural) partials << build_search_results_path(:results) return partials end |