class Fae::PageGenerator

Public Instance Methods

go() click to toggle source
# File lib/generators/fae/page_generator.rb, line 19
def go
  generate_static_page_controller
  generate_static_page_model
  generate_graphql_type
  generate_static_page_view
end
set_globals() click to toggle source
# File lib/generators/fae/page_generator.rb, line 10
def set_globals
  if attributes.present?
    attributes.each do |attr|
      @@attributes[attr.name.to_sym] = convert_attr_type(attr.type)
      @@graphql_attributes << graphql_object(attr)
    end
  end
end

Private Instance Methods

connect_object(object) click to toggle source
# File lib/generators/fae/page_generator.rb, line 53
def connect_object object
  object.constantize.connection
  object
end
convert_attr_type(type) click to toggle source
# File lib/generators/fae/page_generator.rb, line 58
def convert_attr_type(type)
  case type.to_s
  when "string"
    connect_object "Fae::TextField"
  when "text"
    connect_object "Fae::TextArea"
  when "image"
    connect_object "Fae::Image"
  when "file"
    connect_object "Fae::File"
  else
    type
  end
end
generate_graphql_type() click to toggle source
# File lib/generators/fae/page_generator.rb, line 42
def generate_graphql_type
  return unless uses_graphql
  @graphql_attributes = @@graphql_attributes
  template "graphql/graphql_page_type.rb", "app/graphql/types/#{file_name}_page_type.rb"
end
generate_static_page_controller() click to toggle source
# File lib/generators/fae/page_generator.rb, line 28
def generate_static_page_controller
  file = "app/controllers/#{options.namespace}/content_blocks_controller.rb"
  if ::File.exists?(Rails.root.join(file).to_s)
    inject_into_file "app/controllers/#{options.namespace}/content_blocks_controller.rb", ", #{class_name}Page", before: ']'
  else
    template 'controllers/static_pages_controller.rb', file
  end
end
generate_static_page_model() click to toggle source
# File lib/generators/fae/page_generator.rb, line 37
def generate_static_page_model
  @attributes = @@attributes
  template "models/pages_model.rb", "app/models/#{file_name}_page.rb"
end
generate_static_page_view() click to toggle source
# File lib/generators/fae/page_generator.rb, line 48
def generate_static_page_view
  @attributes = @@attributes
  template "views/static_page_form.html.#{options.template}", "app/views/#{options.namespace}/content_blocks/#{file_name}.html.#{options.template}"
end