Module: Broadway::Resource::InstanceMethods
- Defined in:
- lib/broadway/resource.rb
Instance Attribute Summary collapse
-
#asset ⇒ Object
Returns the value of attribute asset.
-
#basename ⇒ Object
where the file is.
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#content ⇒ Object
Returns the value of attribute content.
-
#data ⇒ Object
Returns the value of attribute data.
-
#date ⇒ Object
Returns the value of attribute date.
-
#dir ⇒ Object
where the file is.
-
#ext ⇒ Object
where the file is.
-
#output ⇒ Object
Returns the value of attribute output.
-
#path ⇒ Object
where the file is.
-
#position ⇒ Object
order.
-
#published ⇒ Object
Returns the value of attribute published.
-
#site ⇒ Object
order.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#title ⇒ Object
where the file is.
Instance Method Summary collapse
- #children ⇒ Object
- #excerpt ⇒ Object
-
#id ⇒ Object
The UID for this post (useful in feeds) e.g.
- #layout ⇒ Object
- #menu_title ⇒ Object
- #parent ⇒ Object
- #permalink ⇒ Object
-
#process(options = {}) ⇒ Object
Extract information from the post filename
name
is the String filename of the post file. - #show_children? ⇒ Boolean
-
#tags(context = "tags") ⇒ Object
tags can be stored under multiple contexts default is “tags” (use “categories” or whatever else you want).
- #tags=(value) ⇒ Object
- #tooltip ⇒ Object
Instance Attribute Details
#asset ⇒ Object
Returns the value of attribute asset.
14 15 16 |
# File 'lib/broadway/resource.rb', line 14 def asset @asset end |
#basename ⇒ Object
where the file is
12 13 14 |
# File 'lib/broadway/resource.rb', line 12 def basename @basename end |
#categories ⇒ Object
Returns the value of attribute categories.
14 15 16 |
# File 'lib/broadway/resource.rb', line 14 def categories @categories end |
#content ⇒ Object
Returns the value of attribute content.
13 14 15 |
# File 'lib/broadway/resource.rb', line 13 def content @content end |
#data ⇒ Object
Returns the value of attribute data.
13 14 15 |
# File 'lib/broadway/resource.rb', line 13 def data @data end |
#date ⇒ Object
Returns the value of attribute date.
14 15 16 |
# File 'lib/broadway/resource.rb', line 14 def date @date end |
#dir ⇒ Object
where the file is
12 13 14 |
# File 'lib/broadway/resource.rb', line 12 def dir @dir end |
#ext ⇒ Object
where the file is
12 13 14 |
# File 'lib/broadway/resource.rb', line 12 def ext @ext end |
#output ⇒ Object
Returns the value of attribute output.
13 14 15 |
# File 'lib/broadway/resource.rb', line 13 def output @output end |
#path ⇒ Object
where the file is
12 13 14 |
# File 'lib/broadway/resource.rb', line 12 def path @path end |
#position ⇒ Object
order
10 11 12 |
# File 'lib/broadway/resource.rb', line 10 def position @position end |
#published ⇒ Object
Returns the value of attribute published.
14 15 16 |
# File 'lib/broadway/resource.rb', line 14 def published @published end |
#slug ⇒ Object
Returns the value of attribute slug.
14 15 16 |
# File 'lib/broadway/resource.rb', line 14 def slug @slug end |
#title ⇒ Object
where the file is
12 13 14 |
# File 'lib/broadway/resource.rb', line 12 def title @title end |
Instance Method Details
#children ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/broadway/resource.rb', line 46 def children key = self.categories.last length = self.url.split("/").length @children = site.find_pages_by_category(key) + site.find_posts_by_category(key) @children.delete_if do |child| (child.url == self.url) || (child.url.split("/").length <= length) || (child.is_a?(Broadway::Post) && child.categories != self.categories) || (child.is_a?(Broadway::Page) && child.categories[0..-2] != self.categories) end end |
#excerpt ⇒ Object
78 79 80 |
# File 'lib/broadway/resource.rb', line 78 def excerpt self.data['excerpt'] end |
#id ⇒ Object
The UID for this post (useful in feeds) e.g. /2008/11/05/my-awesome-post
Returns <String>
62 63 64 |
# File 'lib/broadway/resource.rb', line 62 def id File.join(self.dir, self.slug) end |
#layout ⇒ Object
94 95 96 |
# File 'lib/broadway/resource.rb', line 94 def layout self.data and self.data.has_key?("layout") ? self.data["layout"] : self.categories.first end |
#menu_title ⇒ Object
66 67 68 |
# File 'lib/broadway/resource.rb', line 66 def self.data['menu_title'] || self.title end |
#parent ⇒ Object
90 91 92 |
# File 'lib/broadway/resource.rb', line 90 def parent url ? site.find_page_by_url(url[1..-1].split("/").first) : nil end |
#permalink ⇒ Object
74 75 76 |
# File 'lib/broadway/resource.rb', line 74 def permalink self.data['permalink'] end |
#process(options = {}) ⇒ Object
Extract information from the post filename
+name+ is the String filename of the post file
Returns nothing
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/broadway/resource.rb', line 20 def process( = {}) return if .has_key?(:process) and [:process] == false self.read_yaml(path) self.title = data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' ') # If we've added a date and time to the yaml, use that instead of the filename date # Means we'll sort correctly. self.date = Time.parse(self.data["date"].to_s) if self.data.has_key?('date') if self.data.has_key?('published') && self.data['published'] == false self.published = false else self.published = true end if self.data.has_key?("asset") data["asset"]["title"] ||= self.title self.asset = ::Broadway::Asset.new(data["asset"]) end self. = self.data["tags"] self. ||= [] end |
#show_children? ⇒ Boolean
82 83 84 85 86 87 88 |
# File 'lib/broadway/resource.rb', line 82 def show_children? return true if self.data.nil? if self.data.has_key?("show_children") return self.data["show_children"] == "true" || self.data["show_children"] == true end return true end |
#tags(context = "tags") ⇒ Object
tags can be stored under multiple contexts default is “tags” (use “categories” or whatever else you want)
109 110 111 |
# File 'lib/broadway/resource.rb', line 109 def (context = "tags") @tags[context.to_s] end |
#tags=(value) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/broadway/resource.rb', line 98 def (value) @tags = case value when Hash value = value.each { |k, v| value[k] = tag_array(v) } else {"tags" => tag_array(value)} end end |
#tooltip ⇒ Object
70 71 72 |
# File 'lib/broadway/resource.rb', line 70 def tooltip self.data["tooltip"] end |