Class: WebammToRails::Sources::Views::Resource::FormDefinition::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/webamm_to_rails/sources/views/resource/form_definition/presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(crud_definition:, waml_definition:) ⇒ Presenter

Returns a new instance of Presenter.



7
8
9
10
# File 'lib/webamm_to_rails/sources/views/resource/form_definition/presenter.rb', line 7

def initialize(crud_definition:, waml_definition:)
  @crud_definition = crud_definition
  @waml_definition = waml_definition
end

Instance Method Details

#path_nameObject



24
25
26
# File 'lib/webamm_to_rails/sources/views/resource/form_definition/presenter.rb', line 24

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

#renderObject



16
17
18
19
20
21
22
# File 'lib/webamm_to_rails/sources/views/resource/form_definition/presenter.rb', line 16

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

#render?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/webamm_to_rails/sources/views/resource/form_definition/presenter.rb', line 12

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