Class: Brite::Controller
- Inherits:
-
Object
- Object
- Brite::Controller
- Defined in:
- lib/brite/controller.rb
Overview
The Controller class is the primary Brite class, handling the generation of site files.
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Directory of site files on disk.
-
#output ⇒ Object
readonly
Where to save results.
-
#site ⇒ Object
readonly
Returns an instance of Site.
Instance Method Summary collapse
-
#build ⇒ Object
Build the site.
-
#config ⇒ Object
Access to configuration file data.
-
#dryrun? ⇒ Boolean
Is ‘dryrun` mode on? Checks the global variable `$DRYRUN`.
-
#initialize(options = {}) ⇒ Controller
constructor
New Controller.
-
#save(model) ⇒ Object
Save page/post redering to disk.
-
#trace? ⇒ Boolean
Is ‘trace` mode on? Checks global variable `$TRACE`.
-
#url ⇒ Object
URL of site as set in initializer or configuration file.
Constructor Details
#initialize(options = {}) ⇒ Controller
New Controller.
27 28 29 30 31 32 33 34 |
# File 'lib/brite/controller.rb', line 27 def initialize(={}) @location = [:location] || Dir.pwd @output = [:output] #@dryrun = options[:dryrun] #@trace = options[:trace] @site = Site.new(location, :url=>[:url]) end |
Instance Attribute Details
#location ⇒ Object (readonly)
Directory of site files on disk.
40 41 42 |
# File 'lib/brite/controller.rb', line 40 def location @location end |
#output ⇒ Object (readonly)
Where to save results. Usually the templates are shadowed, which means the ouput is the same a location.
44 45 46 |
# File 'lib/brite/controller.rb', line 44 def output @output end |
#site ⇒ Object (readonly)
Returns an instance of Site.
37 38 39 |
# File 'lib/brite/controller.rb', line 37 def site @site end |
Instance Method Details
#build ⇒ Object
Build the site.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/brite/controller.rb', line 72 def build if trace? puts "Layouts: " + site.layouts.map{ |layout| layout.name }.join(", ") puts "Parts: " + site.parts.map{ |part| part.name }.join(", ") puts "Pages: " + site.pages.map{ |page| page.file }.join(", ") puts "Posts: " + site.posts.map{ |post| post.file }.join(", ") puts end Dir.chdir(location) do site.posts.each do |post| puts "Rendering #{post.file}" if $DEBUG save(post) end site.pages.each do |page| puts "Rendering #{page.file}" if $DEBUG save(page) end end puts "\n#{site.pages.size + site.posts.size} Files: #{site.pages.size} Pages, #{site.posts.size} Posts" end |
#config ⇒ Object
Access to configuration file data.
52 53 54 |
# File 'lib/brite/controller.rb', line 52 def config site.config end |
#dryrun? ⇒ Boolean
Is ‘dryrun` mode on? Checks the global variable `$DRYRUN`.
62 63 64 |
# File 'lib/brite/controller.rb', line 62 def dryrun? $DRYRUN #@dryrun end |
#save(model) ⇒ Object
Save page/post redering to disk.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/brite/controller.rb', line 99 def save(model) file = output ? File.join(output, model.output) : model.output text = model.to_s if File.exist?(file) current = File.read(file) else current = nil end if current != text or $FORCE if dryrun? puts " dry run: #{file}" else puts " write: #{file}" File.open(file, 'w'){ |f| f << text } end else puts " unchanged: #{file}" end end |
#trace? ⇒ Boolean
Is ‘trace` mode on? Checks global variable `$TRACE`.
67 68 69 |
# File 'lib/brite/controller.rb', line 67 def trace? $TRACE #@trace end |
#url ⇒ Object
URL of site as set in initializer or configuration file.
57 58 59 |
# File 'lib/brite/controller.rb', line 57 def url site.url end |