Class: Transit::Admin::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/transit/admin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDSL

Returns a new instance of DSL.



72
73
74
75
76
77
78
79
80
# File 'lib/transit/admin.rb', line 72

def initialize
  @fields = ActiveSupport::HashWithIndifferentAccess.new({
    title:      :text_field,
    teaser:     :text_area,
    post_date:  { date_select: { order: [:month, :day, :year], use_short_month: true } },
    image:      :file_field,
    photo:      :file_field
  })
end

Instance Attribute Details

#column_hashObject

Returns the value of attribute column_hash.



26
27
28
# File 'lib/transit/admin.rb', line 26

def column_hash
  @column_hash
end

#columns(*cols) ⇒ Object

Specify the columns to be displayed in the admin. At minimum the name of a method is required. For additional options, use hash syntax.

the proc will be passed a reference to the current object.

config.columns :title, post_date: lambda{ |obj| obj.created_at.to_formatted_s }

Examples:

List a title and post_date column

config.columns :title, :post_date

List a title field, and a post_date field, where post_date uses a proc to describe its value. When called

Overriding the displayed name


config.columns :title, timestamp: { as: 'Post Date' }


44
45
46
# File 'lib/transit/admin.rb', line 44

def columns
  @columns
end

#fields(field_hash = {}) ⇒ Object

Specify the form fields used for each attribute. When inheriting posts or pages defaults are already pre-defined and normally only need to be overridden.

Examples:

Specify a text_area for the title and teaser of a post

config.fields title: :text_area, teaser: :text_area


67
68
69
# File 'lib/transit/admin.rb', line 67

def fields
  @fields
end