Class: Cartoonist::Navigation::Link

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

Constant Summary collapse

@@all =
[]
@@cached_order =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Link

Returns a new instance of Link.



170
171
172
173
174
175
176
177
# File 'lib/cartoonist.rb', line 170

def initialize(options)
  @url = options[:url]
  @preview_url = options[:preview_url]
  @class = options[:class]
  @label = options[:label]
  @title = options[:title]
  @order = options[:order]
end

Instance Attribute Details

#classObject (readonly)

Returns the value of attribute class.



165
166
167
# File 'lib/cartoonist.rb', line 165

def class
  @class
end

#labelObject (readonly)

Returns the value of attribute label.



165
166
167
# File 'lib/cartoonist.rb', line 165

def label
  @label
end

#orderObject (readonly)

Returns the value of attribute order.



165
166
167
# File 'lib/cartoonist.rb', line 165

def order
  @order
end

#preview_urlObject (readonly)

Returns the value of attribute preview_url.



165
166
167
# File 'lib/cartoonist.rb', line 165

def preview_url
  @preview_url
end

#titleObject (readonly)

Returns the value of attribute title.



165
166
167
# File 'lib/cartoonist.rb', line 165

def title
  @title
end

Class Method Details

.add(options) ⇒ Object



198
199
200
201
# File 'lib/cartoonist.rb', line 198

def add(options)
  @@all << Cartoonist::Navigation::Link.new(options)
  @@cached_order = @@all.sort { |x, y| x.order <=> y.order }
end

.allObject



194
195
196
# File 'lib/cartoonist.rb', line 194

def all
  @@cached_order
end

Instance Method Details

#url(preview = false) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/cartoonist.rb', line 179

def url(preview = false)
  if preview && @preview_url
    result = @preview_url
  else
    result = @url
  end

  if result.kind_of? Proc
    result.call
  else
    result
  end
end