Class: Broadway::Slug
- Inherits:
-
Object
- Object
- Broadway::Slug
- Defined in:
- lib/broadway/resources/slug.rb
Class Attribute Summary collapse
-
.styles ⇒ Object
Returns the value of attribute styles.
Instance Attribute Summary collapse
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(slug, resource) ⇒ Slug
constructor
A new instance of Slug.
- #path ⇒ Object
- #permalink ⇒ Object
- #site ⇒ Object
- #template ⇒ Object
- #titleize ⇒ Object
- #to_s ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(slug, resource) ⇒ Slug
Returns a new instance of Slug.
18 19 20 21 |
# File 'lib/broadway/resources/slug.rb', line 18 def initialize(slug, resource) self.value = slug self.resource = resource end |
Class Attribute Details
.styles ⇒ Object
Returns the value of attribute styles.
6 7 8 |
# File 'lib/broadway/resources/slug.rb', line 6 def styles @styles end |
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
3 4 5 |
# File 'lib/broadway/resources/slug.rb', line 3 def resource @resource end |
#scope ⇒ Object
Returns the value of attribute scope.
3 4 5 |
# File 'lib/broadway/resources/slug.rb', line 3 def scope @scope end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/broadway/resources/slug.rb', line 3 def value @value end |
Class Method Details
.default_styles ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/broadway/resources/slug.rb', line 8 def default_styles { :category => "/:categories/:slug", :date => "/:categories/:slug.:format", :category_and_date => "/:categories/:year/:month/:day/:slug", :page => "/:categories/:slug" } end |
Instance Method Details
#path ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/broadway/resources/slug.rb', line 44 def path @path ||= permalink @path ||= resource.sluggify.inject(template) do |result, token| result.gsub(/:#{token.first}/, token.last.nested_parameterize) end.gsub(/#{site.posts_path}/, "").squeeze("/").gsub(/\/$/, "") @path end |
#permalink ⇒ Object
23 24 25 |
# File 'lib/broadway/resources/slug.rb', line 23 def permalink resource.permalink end |
#site ⇒ Object
27 28 29 |
# File 'lib/broadway/resources/slug.rb', line 27 def site resource.site end |
#template ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/broadway/resources/slug.rb', line 31 def template case self.site.permalink_style when :pretty "/:categories/:year/:month/:day/:title" when :none "/:categories/:title.html" when :date "/:categories/:year/:month/:day/:title.html" else self.site.permalink_style.to_s end end |
#titleize ⇒ Object
60 61 62 |
# File 'lib/broadway/resources/slug.rb', line 60 def titleize self.value.split('-').select { |w| w.capitalize! || w }.join(' ') end |
#to_s ⇒ Object
64 65 66 |
# File 'lib/broadway/resources/slug.rb', line 64 def to_s path end |
#url ⇒ Object
52 53 54 |
# File 'lib/broadway/resources/slug.rb', line 52 def url ::File.join(site.url, path) end |