module SunSword class ScaffoldGenerator < Rails::Generators::Base source_root File.expand_path('templates_scaffold', __dir__) argument :arg_structure, type: :string, default: '', banner: '' argument :arg_scope, type: :hash, default: '', banner: 'scope:dashboard' def running setup_variables create_root_folder create_controller_file create_view_file create_link_file end private def setup_variables config = YAML.load_file("db/structures/#{arg_structure}_structure.yaml") @structure = Hashie::Mash.new(config) # Mengambil detail konfigurasi model_name = @structure.model resource_name = @structure.resource_name.singularize.underscore.downcase entity = @structure.entity || {} @actor = @structure.actor @resource_owner_id = @structure.resource_owner_id @uploaders = @structure.uploaders || [] @search_able = @structure.search_able || [] @services = @structure.domains || {} @controllers = @structure.controllers || {} @contract_list = @services.action_list.use_case.contract || [] @contract_fetch_by_id = @services.action_fetch_by_id.use_case.contract || [] @contract_create = @services.action_create.use_case.contract || [] @contract_update = @services.action_update.use_case.contract || [] @contract_destroy = @services.action_destroy.use_case.contract || [] @skipped_fields = entity.skipped_fields || [] @custom_fields = entity.custom_fields || [] @variable_subject = model_name.split('::').last.underscore.downcase @scope_path = resource_name.pluralize.underscore.downcase @scope_class = @scope_path.camelize @model_class = model_name.camelize.constantize @subject_class = resource_name.camelize @fields = contract_fields @form_fields = @controllers.form_fields @route_scope_path = arg_scope['scope'].to_s.downcase rescue '' @route_scope_class = @route_scope_path.camelize rescue '' @mapping_fields = { string: :text_field, text: :text_area, integer: :number_field, float: :number_field, decimal: :number_field, boolean: :check_box, date: :date_select, datetime: :datetime_select, timestamp: :datetime_select, time: :time_select, enum: :select, file: :file_field, files: :file_fields } end def generate_form_fields_html form_fields_html = '' @form_fields.each do |field| field_name = field[:name].to_sym field_type = field[:type].to_sym form_helper = @mapping_fields[field_type] || :text_field input_id = "#{@variable_subject}_#{field_name}" label_input_id = case form_helper when :date_select, :datetime_select then "#{input_id}_1i" # Year when :time_select then "#{input_id}_4i" # Hour else input_id end field_html = <<-HTML
or drag and drop
PNG, JPG, GIF, DOC etc.
or drag and drop
PNG, JPG, GIF, DOC etc.