Sha256: 8acf621e8dc80249c6787a2dcaecfb1c771e3989febc7efd04df2405c6f42519

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

module WebammToRails
  module Sources
    module Views
      module Resource
        module IndexDefinition
          class Presenter
            def initialize(crud_definition:)
              @crud_definition = crud_definition
            end

            def render?
              @crud_definition.actions.find { |action| action.name == 'index' }.present?
            end

            def render
              template_path = File.expand_path('template.erb', __dir__)
              template_content = File.read(template_path)
              raw_content = ERB.new(template_content, trim_mode: '-').result(instance_eval { binding })
              
              ::WebammToRails::Utils::FormatTemplate.call(raw_content)
            end

            def path_name
              "app/views/#{resource_name}/index.html.erb"
            end

            private

            def resource_name
              @crud_definition.table
            end

            def title
              @crud_definition.table.humanize
            end

            def enabled?(view_action)
              @crud_definition.actions.find { |action| action.name == view_action }.present?
            end

            def new_resource_path
              "new_#{resource_name.singularize}_path"
            end

            def edit_resource_path
              "edit_#{resource_name.singularize}_path(#{resource_name.singularize})"
            end

            def resource_path
              "#{resource_name.singularize}_path(#{resource_name.singularize})"
            end

            def singular_variable
              resource_name.singularize
            end

            def plural_variable
              resource_name 
            end

            def model_attributes
              @crud_definition.actions.find { |action| action.name == 'index' }.options.model_attributes
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webamm_to_rails-7.0.1 lib/webamm_to_rails/sources/views/resource/index_definition/presenter.rb
webamm_to_rails-7.0.0 lib/webamm_to_rails/sources/views/resource/index_definition/presenter.rb