Class: Broadway::Site

Inherits:
Object
  • Object
show all
Includes:
Configurable, Processable, Resourceful
Defined in:
lib/broadway/resources/site.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Configurable

included

Methods included from Processable

included

Methods included from Resourceful

included

Constructor Details

#initialize(settings) ⇒ Site

Returns a new instance of Site.



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

def initialize(settings)
  self.processor = Broadway::Processor::Site.new(self, settings)
end

Instance Attribute Details

#assetsObject

Returns the value of attribute assets.



8
9
10
# File 'lib/broadway/resources/site.rb', line 8

def assets
  @assets
end

#categoriesObject

Returns the value of attribute categories.



8
9
10
# File 'lib/broadway/resources/site.rb', line 8

def categories
  @categories
end

#configurationObject

Returns the value of attribute configuration.



8
9
10
# File 'lib/broadway/resources/site.rb', line 8

def configuration
  @configuration
end

#filesObject

Returns the value of attribute files.



8
9
10
# File 'lib/broadway/resources/site.rb', line 8

def files
  @files
end

#layoutsObject

Returns the value of attribute layouts.



8
9
10
# File 'lib/broadway/resources/site.rb', line 8

def layouts
  @layouts
end

Returns the value of attribute links.



8
9
10
# File 'lib/broadway/resources/site.rb', line 8

def links
  @links
end

#postsObject

Returns the value of attribute posts.



8
9
10
# File 'lib/broadway/resources/site.rb', line 8

def posts
  @posts
end

#rootsObject

Returns the value of attribute roots.



8
9
10
# File 'lib/broadway/resources/site.rb', line 8

def roots
  @roots
end

#tagsObject

Returns the value of attribute tags.



8
9
10
# File 'lib/broadway/resources/site.rb', line 8

def tags
  @tags
end

Instance Method Details

#build!Object



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

def build!
  processor.build
end

#dataObject



58
59
60
# File 'lib/broadway/resources/site.rb', line 58

def data
  settings
end

#find(type, attributes) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/broadway/resources/site.rb', line 95

def find(type, attributes)
  result = []
  self.send(type.to_s.pluralize).each do |resource|
    failed_to_match = false
    attributes.each do |method, value|
      if resource.respond_to?(method)
        failed_to_match = (resource.send(method) != value)
      else
        failed_to_match = !resource.send(method.to_s.pluralize).include?(value)
      end
      break if failed_to_match
    end
    result << resource unless failed_to_match
  end
  result
end

#first(type, attributes) ⇒ Object



112
113
114
# File 'lib/broadway/resources/site.rb', line 112

def first(type, attributes)
  find(type, attributes).first
end

#generate(&block) ⇒ Object



26
27
28
# File 'lib/broadway/resources/site.rb', line 26

def generate(&block)
  processor.generate(&block)
end

#generate!Object



22
23
24
# File 'lib/broadway/resources/site.rb', line 22

def generate!
  processor.generate
end

#index_pathObject



38
39
40
# File 'lib/broadway/resources/site.rb', line 38

def index_path
  settings[:index_path]
end

#languageObject



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

def language
  settings[:language]
end


168
169
170
# File 'lib/broadway/resources/site.rb', line 168

def menu(name)
  link_roots_by_category(name)
end

#num_pagesObject



160
161
162
# File 'lib/broadway/resources/site.rb', line 160

def num_pages
  pages.length
end

#num_postsObject



156
157
158
# File 'lib/broadway/resources/site.rb', line 156

def num_posts
  posts.length
end

#pagesObject



164
165
166
# File 'lib/broadway/resources/site.rb', line 164

def pages
  posts.select { |post| post.kind == "page" }
end


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

def permalink_style
  settings[:permalink].to_sym
end

#posts_pathObject



82
83
84
# File 'lib/broadway/resources/site.rb', line 82

def posts_path
  self.settings[:posts]
end

#production_urlObject



34
35
36
# File 'lib/broadway/resources/site.rb', line 34

def production_url
  settings[:production_url]
end

#public_pathObject



46
47
48
# File 'lib/broadway/resources/site.rb', line 46

def public_path
  settings[:public_path]
end

#renderObject

While in Jekyll this method renders the content explicitly, I’m using Sinatra, partly because I like having the flexibility of using their get/post methods, and partly because I don’t have the time/desire to try to hack jekyll to use haml. I’d rather just start over



91
92
93
# File 'lib/broadway/resources/site.rb', line 91

def render
  server.render
end

#setting(path) ⇒ Object



50
51
52
# File 'lib/broadway/resources/site.rb', line 50

def setting(path)
  configuration.get(path)
end

#settingsObject



54
55
56
# File 'lib/broadway/resources/site.rb', line 54

def settings
  configuration.settings
end

#setupObject



74
75
76
# File 'lib/broadway/resources/site.rb', line 74

def setup
  configuration.setup
end

#sourceObject



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

def source
  self.settings[:source]
end

#titleObject



62
63
64
# File 'lib/broadway/resources/site.rb', line 62

def title
  settings[:title]
end

#urlObject



30
31
32
# File 'lib/broadway/resources/site.rb', line 30

def url
  settings[:url] || "http://localhost"
end

#views_pathObject



42
43
44
# File 'lib/broadway/resources/site.rb', line 42

def views_path
  settings[:views_path]
end