module HotGlue::GeneratorHelper

Public Instance Methods

derrive_reference_name(thing_as_string) click to toggle source
# File lib/generators/hot_glue/scaffold_generator.rb, line 14
def derrive_reference_name thing_as_string
  assoc_class = eval(thing_as_string)

  if assoc_class.respond_to?("name")
    display_column = "name"
  elsif assoc_class.respond_to?("to_label")
    display_column = "to_label"
  elsif assoc_class.respond_to?("full_name")
    display_column = "full_name"
  elsif assoc_class.respond_to?("display_name")
    display_column = "display_name"
  elsif assoc_class.respond_to?("email")
    display_column = "email"
  else
    raise("this should have been caught by the checker in the initializer")
    # puts "*** Oops: Can't find any column to use as the display label for the #{assoc.name.to_s} association on the #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, or 5) email directly on your #{assoc.class_name} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
  end
  display_column
end
text_area_output(col, field_length, col_identifier ) click to toggle source
# File lib/generators/hot_glue/scaffold_generator.rb, line 35
def text_area_output(col, field_length, col_identifier )
  lines = field_length % 40
  if lines > 5
    lines = 5
  end

  "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
= f.text_area :#{col.to_s}, class: 'form-control', cols: 40, rows: '#{lines}'
%label.form-text
  #{col.to_s.humanize}\n"
end