Class: Entitled::Titles

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

Constant Summary collapse

DEFAULT_TITLES_PER_PAGE =
1

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ Titles

Returns a new instance of Titles.



140
141
142
143
144
# File 'lib/entitled/entitled.rb', line 140

def initialize controller
  @controller       = controller
  @titles           = []
  @resources_titles = []
end

Class Attribute Details

.per_pageObject

Returns the value of attribute per_page.



135
136
137
# File 'lib/entitled/entitled.rb', line 135

def per_page
  @per_page
end

.prefix_exceptionsObject

Returns the value of attribute prefix_exceptions.



135
136
137
# File 'lib/entitled/entitled.rb', line 135

def prefix_exceptions
  @prefix_exceptions
end

.site_titleObject

Returns the value of attribute site_title.



135
136
137
# File 'lib/entitled/entitled.rb', line 135

def site_title
  @site_title
end

Instance Attribute Details

Returns the value of attribute breadcrumbs.



137
138
139
# File 'lib/entitled/entitled.rb', line 137

def breadcrumbs
  @breadcrumbs
end

#headingsObject (readonly)

Returns the value of attribute headings.



137
138
139
# File 'lib/entitled/entitled.rb', line 137

def headings
  @headings
end

#tagObject (readonly)

Returns the value of attribute tag.



137
138
139
# File 'lib/entitled/entitled.rb', line 137

def tag
  @tag
end

#upObject (readonly)

Returns the value of attribute up.



137
138
139
# File 'lib/entitled/entitled.rb', line 137

def up
  @up
end

Instance Method Details

#add(*objects) ⇒ Object



164
165
166
# File 'lib/entitled/entitled.rb', line 164

def add *objects
  objects.each { |object| @titles << ResourceTitle.new(object) }
end

#add_collection(class_name, first) ⇒ Object



154
155
156
# File 'lib/entitled/entitled.rb', line 154

def add_collection class_name, first
  @titles << CollectionTitle.new(class_name, first)
end

#add_resource(resource_or_string) ⇒ Object



158
159
160
161
162
# File 'lib/entitled/entitled.rb', line 158

def add_resource resource_or_string
  resource_title = ResourceTitle.new(resource_or_string)
  @titles           << resource_title
  @resources_titles << resource_title if resource_title.resource?
end

#generate(view) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/entitled/entitled.rb', line 146

def generate view
  @view = view
  add_title_for_new_or_create
  @breadcrumbs = compact_titles(@titles)
  @headings    = compact_titles(page_titles, false)
  @tag         = generate_tag
end

#resource_class?(klass_name) ⇒ Boolean

Returns:

  • (Boolean)


172
173
174
175
# File 'lib/entitled/entitled.rb', line 172

def resource_class? klass_name
  @resources_titles.each { |title| return title.resource if title.resource.class.name == klass_name }
  false
end

#resources?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/entitled/entitled.rb', line 168

def resources?
  @resources_titles.any?
end