Module: Broadway::Resource::InstanceMethods

Defined in:
lib/broadway/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assetObject

Returns the value of attribute asset.



14
15
16
# File 'lib/broadway/resource.rb', line 14

def asset
  @asset
end

#basenameObject

where the file is



12
13
14
# File 'lib/broadway/resource.rb', line 12

def basename
  @basename
end

#categoriesObject

Returns the value of attribute categories.



14
15
16
# File 'lib/broadway/resource.rb', line 14

def categories
  @categories
end

#contentObject

Returns the value of attribute content.



13
14
15
# File 'lib/broadway/resource.rb', line 13

def content
  @content
end

#dataObject

Returns the value of attribute data.



13
14
15
# File 'lib/broadway/resource.rb', line 13

def data
  @data
end

#dateObject

Returns the value of attribute date.



14
15
16
# File 'lib/broadway/resource.rb', line 14

def date
  @date
end

#dirObject

where the file is



12
13
14
# File 'lib/broadway/resource.rb', line 12

def dir
  @dir
end

#extObject

where the file is



12
13
14
# File 'lib/broadway/resource.rb', line 12

def ext
  @ext
end

#outputObject

Returns the value of attribute output.



13
14
15
# File 'lib/broadway/resource.rb', line 13

def output
  @output
end

#pathObject

where the file is



12
13
14
# File 'lib/broadway/resource.rb', line 12

def path
  @path
end

#positionObject

order



10
11
12
# File 'lib/broadway/resource.rb', line 10

def position
  @position
end

#publishedObject

Returns the value of attribute published.



14
15
16
# File 'lib/broadway/resource.rb', line 14

def published
  @published
end

#siteObject

order



10
11
12
# File 'lib/broadway/resource.rb', line 10

def site
  @site
end

#slugObject

Returns the value of attribute slug.



14
15
16
# File 'lib/broadway/resource.rb', line 14

def slug
  @slug
end

#titleObject

where the file is



12
13
14
# File 'lib/broadway/resource.rb', line 12

def title
  @title
end

Instance Method Details

#childrenObject



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

#excerptObject



78
79
80
# File 'lib/broadway/resource.rb', line 78

def excerpt
  self.data['excerpt']
end

#idObject

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

#layoutObject



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


66
67
68
# File 'lib/broadway/resource.rb', line 66

def menu_title
  self.data['menu_title'] || self.title
end

#parentObject



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


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(options = {})
  return if options.has_key?(:process) and options[: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.tags = self.data["tags"]
  self.tags ||= []
end

#show_children?Boolean

Returns:

  • (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 tags(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 tags=(value)
  @tags = case value
  when Hash
    value = value.each { |k, v| value[k] = tag_array(v) }
  else
    {"tags" => tag_array(value)}
  end
end

#tooltipObject



70
71
72
# File 'lib/broadway/resource.rb', line 70

def tooltip
  self.data["tooltip"]
end