class AmsLayout::Writer

Attributes

class_name[W]

Public Instance Methods

aliases() click to toggle source
# File lib/ams_layout/writer.rb, line 27
def aliases
  @aliases ||= {}
end
aliases=(data) click to toggle source
# File lib/ams_layout/writer.rb, line 31
def aliases=(data)
  @aliases = Hash(data)
end
class_name() click to toggle source
# File lib/ams_layout/writer.rb, line 23
def class_name
  @class_name ||= AmsLayout.configuration.layout_class_name
end
source_file_name() click to toggle source

attr_writer :aliases

# File lib/ams_layout/writer.rb, line 19
def source_file_name
  class_name.ams_layout_snakecase + '.rb'
end
write(stream, layout) click to toggle source
# File lib/ams_layout/writer.rb, line 35
def write stream, layout
  stream << header

  layout.each do |section_label, fields|
    stream << section(section_label)

    fields.each do |fld|
      stream << field(fld[:label], fld[:id], fld[:type])
      write_aliases stream, fld[:label], fld[:id], fld[:type]
    end # fields
  end # layout

  stream << footer
end

Private Instance Methods

field(label, id, type) click to toggle source
# File lib/ams_layout/writer.rb, line 90
    def field label, id, type
      case type
      when 'text'
        typed_field = 'text_field'
      when 'textarea'
        typed_field = 'text_area'
      when 'select'
        typed_field = 'select_list'
      when 'checkbox'
        typed_field = 'checkbox'
      when 'button'
        typed_field = 'button'
      else
        typed_field = '# unknown_field_type'
      end

      field_label = label.ams_layout_snakecase
      text =<<TEXT
  #{typed_field}(:#{field_label}, id: '#{id}')
TEXT
    end
field_alias(label, id, type) click to toggle source
# File lib/ams_layout/writer.rb, line 112
def field_alias label, id, type
  text = "  #{field(label, id, type)}"
end
header() click to toggle source
# File lib/ams_layout/writer.rb, line 59
    def header
      text =<<TEXT
#############################################################################
# #{source_file_name}
#
# This file has been generated by AmsLayout.
# Do not modify this file manually.
#
#############################################################################

require 'pathname'
require Pathname(__FILE__).ascend{|d| h=d+'support_helper.rb'; break h if h.file?}
require 'page-object'

class #{class_name}
  include PageObject

  #
  # Fields (ordered by section as seen on screen)
  #
TEXT
    end
section(label) click to toggle source
# File lib/ams_layout/writer.rb, line 82
    def section label
      text =<<TEXT


  # Section: #{label}
TEXT
    end
write_aliases(stream, label, id, type) click to toggle source
# File lib/ams_layout/writer.rb, line 52
def write_aliases stream, label, id, type
  label_aliases = aliases.key?(label) ? aliases[label] : []
  label_aliases.each do |al|
    stream << field_alias(al, id, type)
  end
end