Class: Infold::Views::BaseWriter

Inherits:
BaseWriter show all
Defined in:
lib/infold/writers/views/base_writer.rb

Direct Known Subclasses

FormWriter, IndexWriter, ShowWriter

Instance Attribute Summary collapse

Attributes inherited from BaseWriter

#resource

Instance Method Summary collapse

Methods inherited from BaseWriter

#edit_path, #indent, #index_path, #new_path, #resource_name, #show_path

Constructor Details

#initialize(resource, app_title = nil) ⇒ BaseWriter

Returns a new instance of BaseWriter.



8
9
10
11
# File 'lib/infold/writers/views/base_writer.rb', line 8

def initialize(resource, app_title=nil)
  @resource = resource
  @app_title = app_title || @resource.name
end

Instance Attribute Details

#app_titleObject (readonly)

Returns the value of attribute app_title.



6
7
8
# File 'lib/infold/writers/views/base_writer.rb', line 6

def app_title
  @app_title
end

Instance Method Details

#field_display_code(field, part, model_name: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/infold/writers/views/base_writer.rb', line 13

def field_display_code(field, part, model_name: nil)
  field_code = "#{model_name || resource_name(:snake)}.#{field.name}"
  if part == :csv
    "= #{field_code}#{'_i18n' if field.enum}"
  else
    if field.association&.belongs_to?
      belongs_to_field_display(field.association, model_name)
    elsif field.active_storage
      active_storage_field_display(field, part, field_code)
    elsif field.enum&.has_color?
      "= render Admin::BadgeComponent.new(#{field_code}_i18n, #{field_code}_color)"
    elsif field.enum
      "= #{field_code}_i18n"
    elsif field.decorator || field.type == :boolean
      "= #{field_code}_display"
    else
      "= #{field_code}"
    end
  end
end