module Adminpanel::ResourceGeneratorHelper
Public Instance Methods
assign_attributes_variables(attribute)
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 26 def assign_attributes_variables(attribute) @attr_field = attribute.split(":").first if attribute.split(":").second.nil? @attr_type = "string" else @attr_type = attribute.split(":").second end end
associations()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 177 def associations association = "" fields.each do |attribute| assign_attributes_variables(attribute) case @attr_type when 'belongs_to' association = "#{association}#{belongs_to_association(@attr_field)}" when 'checkbox' association = "#{association}#{checkbox_association(@attr_field)}" when 'image', 'file' association = "#{association}#{file_association(@attr_field)}" end end if has_gallery? association = "#{association}mount_images :#{gallery_name.pluralize}\n\t\t" end association end
attribute_hash(name, type, model = '')
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 134 def attribute_hash(name, type, model = '') model = model_type(model) + ",\n" if model != '' "{\n" + indent("'#{name}'" + " => {\n", 2) + indent(form_type(type), 4) + ",\n" + indent(label_type, 4) + ",\n" + indent(placeholder_type, 4) + ",\n" + indent(model, 4) + indent("}\n", 2) + '}' end
belongs_to_association(field)
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 198 def belongs_to_association(field) "belongs_to :#{field.singularize.downcase}\n\t\t" end
belongs_to_field(resource)
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 14 def belongs_to_field(resource) "#{resource.singularize.downcase}_id" end
belongs_to_form_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 122 def belongs_to_form_hash attribute_hash(belongs_to_field(@attr_field), 'select', resource_class_name(@attr_field)) end
boolean_form_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 110 def boolean_form_hash attribute_hash(@attr_field, 'boolean') end
camelized_resource()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 57 def camelized_resource resource_name.camelize end
checkbox_association(field)
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 202 def checkbox_association(field) return "# has_many :#{@attr_field.downcase}zations\n\t\t" + "# has_many :#{@attr_field.pluralize.downcase}, " + "through: :#{@attr_field.downcase}zations, " + "dependent: :destroy\n\t\t" end
checkbox_field(resource)
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 18 def checkbox_field(resource) "#{resource.singularize.downcase}_ids" end
checkbox_form_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 126 def checkbox_form_hash attribute_hash( checkbox_field(resource_class_name(@attr_field.downcase.singularize + 's')), 'checkbox', @attr_field.capitalize.singularize ) end
class_name()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 10 def class_name "#{resource_name}_#{@attr_field}".camelize end
date_form_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 114 def date_form_hash attribute_hash(@attr_field, 'datepicker') end
file_association(field)
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 209 def file_association(field) "mount_uploader :#{field}, #{class_name}Uploader\n\t\t" end
file_field_form_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 118 def file_field_form_hash attribute_hash(gallery_name.pluralize, 'adminpanel_file_field') end
file_form_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 102 def file_form_hash attribute_hash(@attr_field, 'file_field') end
float_form_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 90 def float_form_hash attribute_hash(@attr_field, 'text_field') end
form_attributes_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 79 def form_attributes_hash fields.map do |attribute| assign_attributes_variables(attribute) send(@attr_type + '_form_hash') end.join(", \n") end
form_type(type)
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 146 def form_type(type) "'type' => '#{type}'" end
gallery_name()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 53 def gallery_name "#{resource_name}file" #ex: postfile end
has_associations?()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 164 def has_associations? fields.each do |attribute| assign_attributes_variables(attribute) if( @attr_type == 'belongs_to' || @attr_type == 'checkbox' || @attr_type == 'file' || has_gallery?) return true end end return false end
has_gallery?()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 45 def has_gallery? !options[:'skip-gallery'] end
image_form_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 106 def image_form_hash attribute_hash(@attr_field, 'image_field') end
integer_form_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 98 def integer_form_hash attribute_hash(@attr_field, 'number_field') end
is_a_resource?()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 35 def is_a_resource? fields.each do |attribute| assign_attributes_variables(attribute) if @attr_type != 'belongs_to' return true end end false end
label_type()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 150 def label_type "'label' => '#{@attr_field}'" end
model_type(model_name)
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 158 def model_type(model_name) "'options' => Proc.new { |#{resource_name.downcase}_instance|\n" + indent("Adminpanel::#{model_name}.all\n", 2) + '}' end
needs_name?()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 3 def needs_name? fields.each do |attribute| return false if attribute.split(':').first == 'name' end true end
placeholder_type()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 154 def placeholder_type "'placeholder' => '#{@attr_field}'" end
pluralized_name()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 61 def pluralized_name "#{resource_name.pluralize}" end
resource_class_name(resource)
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 22 def resource_class_name(resource) "#{resource.singularize.capitalize}" end
resource_name()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 49 def resource_name name.singularize.downcase #normalize name to downcase and singular end
string_form_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 86 def string_form_hash attribute_hash(@attr_field, 'text_field') end
symbolized_attributes()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 65 def symbolized_attributes fields.map do |attribute| assign_attributes_variables(attribute) case @attr_type when 'belongs_to' ":#{belongs_to_field(@attr_field)}" when 'checkbox' "{ #{checkbox_field(@attr_field)}: [] }" else ":#{attribute.split(':').first}" end end.join(",\n") end
text_form_hash()
click to toggle source
# File lib/generators/adminpanel/resource/resource_generator_helper.rb, line 94 def text_form_hash attribute_hash(@attr_field ,'wysiwyg_field') end