brite 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. data/.ruby +56 -0
  2. data/COPYING.rdoc +30 -0
  3. data/HISTORY.rdoc +16 -2
  4. data/README.rdoc +35 -27
  5. data/bin/brite-server +1 -1
  6. data/lib/brite.rb +2 -1
  7. data/lib/brite.yml +56 -0
  8. data/lib/brite/command.rb +100 -55
  9. data/lib/brite/config.rb +122 -40
  10. data/lib/brite/controller.rb +46 -104
  11. data/lib/brite/layout.rb +27 -13
  12. data/lib/brite/model.rb +107 -0
  13. data/lib/brite/page.rb +229 -0
  14. data/lib/brite/part.rb +88 -0
  15. data/lib/brite/post.rb +41 -0
  16. data/lib/brite/server.rb +88 -93
  17. data/lib/brite/site.rb +150 -0
  18. data/lib/brite/version.rb +21 -0
  19. data/test/fixture/brite.yml +3 -0
  20. data/test/fixture/example-page.page +8 -0
  21. data/test/fixture/example-post.post +9 -0
  22. data/test/helper.rb +5 -0
  23. data/test/test_config.rb +23 -0
  24. data/test/test_page.rb +28 -0
  25. data/test/test_site.rb +37 -0
  26. metadata +104 -109
  27. data/LICENSE +0 -205
  28. data/Syckfile +0 -76
  29. data/lib/brite/meta/data.rb +0 -26
  30. data/lib/brite/meta/package +0 -8
  31. data/lib/brite/meta/profile +0 -19
  32. data/lib/brite/models/model.rb +0 -97
  33. data/lib/brite/models/page.rb +0 -142
  34. data/lib/brite/models/post.rb +0 -9
  35. data/lib/brite/models/site.rb +0 -46
  36. data/lib/brite/rackup.rb +0 -6
  37. data/lib/plugins/sow/brite/awesome/Sowfile +0 -11
  38. data/lib/plugins/sow/brite/awesome/about.page +0 -28
  39. data/lib/plugins/sow/brite/awesome/assets/custom.less +0 -96
  40. data/lib/plugins/sow/brite/awesome/assets/fade.png +0 -0
  41. data/lib/plugins/sow/brite/awesome/assets/highlight.css +0 -96
  42. data/lib/plugins/sow/brite/awesome/assets/highlight.js +0 -1
  43. data/lib/plugins/sow/brite/awesome/assets/jquery.js +0 -19
  44. data/lib/plugins/sow/brite/awesome/assets/jquery.tabs.js +0 -1
  45. data/lib/plugins/sow/brite/awesome/assets/reset.css +0 -57
  46. data/lib/plugins/sow/brite/awesome/assets/ruby.png +0 -0
  47. data/lib/plugins/sow/brite/awesome/brite.yaml +0 -3
  48. data/lib/plugins/sow/brite/awesome/history.page +0 -15
  49. data/lib/plugins/sow/brite/awesome/index.page +0 -18
  50. data/lib/plugins/sow/brite/awesome/legal.page +0 -28
  51. data/lib/plugins/sow/brite/awesome/logs.page +0 -14
  52. data/lib/plugins/sow/brite/awesome/page.layout +0 -75
  53. data/lib/plugins/sow/brite/blog1/.rsync-filter +0 -12
  54. data/lib/plugins/sow/brite/blog1/2011/01/sample.html +0 -293
  55. data/lib/plugins/sow/brite/blog1/2011/01/sample.post +0 -44
  56. data/lib/plugins/sow/brite/blog1/Sowfile +0 -10
  57. data/lib/plugins/sow/brite/blog1/assets/images/bg.jpg +0 -0
  58. data/lib/plugins/sow/brite/blog1/assets/images/icon.jpg +0 -0
  59. data/lib/plugins/sow/brite/blog1/assets/styles/class.css +0 -15
  60. data/lib/plugins/sow/brite/blog1/assets/styles/id.css +0 -85
  61. data/lib/plugins/sow/brite/blog1/assets/styles/misc.css +0 -0
  62. data/lib/plugins/sow/brite/blog1/assets/styles/print.css +0 -76
  63. data/lib/plugins/sow/brite/blog1/assets/styles/reset.css +0 -77
  64. data/lib/plugins/sow/brite/blog1/assets/styles/tag.css +0 -68
  65. data/lib/plugins/sow/brite/blog1/brite.yml +0 -3
  66. data/lib/plugins/sow/brite/blog1/index.page +0 -23
  67. data/lib/plugins/sow/brite/blog1/page.layout +0 -88
  68. data/lib/plugins/sow/brite/blog1/post.layout +0 -25
  69. data/meta/data.rb +0 -26
  70. data/meta/package +0 -8
  71. data/meta/profile +0 -19
@@ -7,32 +7,48 @@ module Brite
7
7
  class Config
8
8
 
9
9
  # Configuration file name glob.
10
- CONFIG_FILE = '{.brite,brite.yml,brite.yaml}'
10
+ CONFIG_FILE = '{.brite,brite.yml,brite.yaml}'
11
11
 
12
12
  # Default URL, which is just for testing purposes.
13
- DEFAULT_URL = 'http://0.0.0.0:4321'
13
+ DEFAULT_URL = 'http://0.0.0.0:3000'
14
14
 
15
15
  # Default stencil.
16
- DEFAULT_STENCIL = 'rhtml' #'liquid' # 'rhtml'
16
+ DEFAULT_STENCIL = 'erb'
17
17
 
18
18
  # Default format.
19
- DEFAULT_FORMAT = nil #html
19
+ DEFAULT_FORMAT = nil #html
20
20
 
21
21
  # Default page layout file name (less `.layout` extension).
22
- DEFAULT_PAGE_LAYOUT = 'page'
22
+ DEFAULT_PAGE_LAYOUT = 'page'
23
23
 
24
24
  # Default post layout file name (less `.layout` extension).
25
- DEFAULT_POST_LAYOUT = 'post'
25
+ DEFAULT_POST_LAYOUT = 'post'
26
26
 
27
- # Location of brite files.
27
+ # Default page route (`:path`).
28
+ DEFAULT_PAGE_ROUTE = ':path'
29
+
30
+ # Default post route (`:path`).
31
+ DEFAULT_POST_ROUTE = ':path'
32
+
33
+ # Default author for pages and posts.
34
+ DEFAULT_AUTHOR = 'Anonymous'
35
+
36
+ # Default location of layouts.
37
+ DEFAULT_LAYOUT_PATH = ['assets/layouts']
38
+
39
+ # Default location of partials.
40
+ DEFAULT_PARTIAL_PATH = ['assets/partials']
41
+
42
+ # Location of brite project files. By necessity the configuration file
43
+ # will be located in this directory.
28
44
  attr :location
29
45
 
46
+ # Configuration file.
47
+ attr :file
48
+
30
49
  # Site's absolute URL. Where possible links are relative,
31
50
  # but it is not alwasy possible. So a URL should *ALWAYS*
32
51
  # be provided for the site.
33
- #--
34
- # TODO: Allow +url+ to be set via the command line when generating the site.
35
- #++
36
52
  attr_accessor :url
37
53
 
38
54
  # Defaut section template engine.
@@ -47,23 +63,51 @@ module Brite
47
63
  # Default post layout file name (less extension).
48
64
  attr_accessor :post_layout
49
65
 
66
+ # Default page route.
67
+ attr_accessor :page_route
68
+
69
+ # Default post route.
70
+ attr_accessor :post_route
71
+
72
+ # Default author.
73
+ attr_accessor :author
74
+
75
+ # Paths to look for layouts.
76
+ attr_accessor :layout_path
77
+
78
+ # Paths to look for layouts.
79
+ attr_accessor :partial_path
80
+
50
81
  # New instance of Config.
51
82
  def initialize(location=nil)
52
- @location = location || Dir.pwd
83
+ @location = location || Dir.pwd
84
+ @file = Dir.glob(File.join(@location, CONFIG_FILE)).first
85
+
86
+ @url = DEFAULT_URL
87
+ @stencil = DEFAULT_STENCIL
88
+ @format = DEFAULT_FORMAT
89
+
90
+ @page_layout = DEFAULT_PAGE_LAYOUT
91
+ @post_layout = DEFAULT_POST_LAYOUT
53
92
 
54
- @url = DEFAULT_URL
55
- @stencil = DEFAULT_STENCIL
56
- @format = DEFAULT_FORMAT
93
+ @page_route = DEFAULT_PAGE_ROUTE
94
+ @post_route = DEFAULT_POST_ROUTE
57
95
 
58
- @page_layout = DEFAULT_PAGE_LAYOUT
59
- @post_layout = DEFAULT_POST_LAYOUT
96
+ @author = DEFAULT_AUTHOR
97
+
98
+ @layout_path = DEFAULT_LAYOUT_PATH
99
+ @partial_path = DEFAULT_PARTIAL_PATH
100
+
101
+ @custom = {}
60
102
 
61
103
  configure
62
104
  end
63
105
 
106
+ #
64
107
  # Load configuration file.
108
+ #
65
109
  def configure
66
- if file = Dir[File.join(location, CONFIG_FILE)].first
110
+ if file
67
111
  data = YAML.load(File.new(file))
68
112
  data.each do |k,v|
69
113
  __send__("#{k}=", v)
@@ -71,32 +115,70 @@ module Brite
71
115
  end
72
116
  end
73
117
 
74
- #def initialize_defaults
75
- # if file = Dir['{.,}config/defaults{,.yml,.yaml}'].first
76
- # custom_defaults = YAML.load(File.new(file))
77
- # else
78
- # custom_defaults = {}
79
- # end
80
- # @defaults = OpenStruct.new(DEFAULTS.merge(custom_defaults))
81
- #end
82
-
83
- # FIXME: Is this used? What about page vs pagelayout?
84
- #def defaults
85
- # @defaults ||= OpenStruct.new(
86
- # :stencil => stencil,
87
- # :format => format,
88
- # :pagelayout => page,
89
- # :postlayout => post
90
- # )
91
- #end
92
-
93
- # Use Gemdo.
94
- def gemdo=(set)
118
+ #
119
+ # Make sure layout_path is a list.
120
+ #
121
+ def layout_path=(path)
122
+ @layout_path = [path].flatten
123
+ end
124
+
125
+ #
126
+ # Make sure partial_path is a list.
127
+ #
128
+ def partial_path=(path)
129
+ @partial_path = [path].flatten
130
+ end
131
+
132
+ =begin
133
+ #
134
+ # Locate a layout looking in layout paths.
135
+ #
136
+ def find_layout(name)
137
+ # look for layout in layout_path locations
138
+ file = nil
139
+ @layout_path.find do |path|
140
+ file = Dir.glob(File.join(path, "#{name}.layout")).first
141
+ end
142
+ # fallback to site's root location
143
+ if !file
144
+ file = Dir.glob(File.join(@location, "#{name}.layout")).first
145
+ end
146
+ # if not found raise an error
147
+ raise "Cannot locate layout #{name}." unless file
148
+ # return layout file
149
+ file
150
+ end
151
+ =end
152
+
153
+ #
154
+ # Provide access to POM.
155
+ #
156
+ # @todo Will become GemDo in future ?
157
+ #
158
+ def pom=(set)
95
159
  return unless set
96
- require 'gemdo'
160
+ require 'pom'
97
161
  Brite::Context.class_eval do
98
162
  def project
99
- @project ||= Gemdo::Project.new
163
+ @project ||= POM::Project.new
164
+ end
165
+ end
166
+ end
167
+
168
+ #
169
+ alias_method :gemdo=, :pom=
170
+
171
+ #
172
+ def method_missing(s, v=nil, *a, &b)
173
+ s = s.to_s
174
+ case s
175
+ when /=$/
176
+ @custom[s.chomp('=')] = v
177
+ else
178
+ if @custom.key?(s)
179
+ @custom[s]
180
+ else
181
+ super(s.to_sym, v, *a, &b)
100
182
  end
101
183
  end
102
184
  end
@@ -1,159 +1,101 @@
1
1
  require 'neapolitan'
2
2
  require 'brite/config'
3
3
  require 'brite/layout'
4
- require 'brite/models/site'
5
- require 'brite/models/page'
6
- require 'brite/models/post'
4
+ require 'brite/site'
5
+ require 'brite/page'
6
+ require 'brite/post'
7
+ require 'brite/part'
7
8
 
8
9
  module Brite
9
10
 
10
11
  # The Controller class is the primary Brite class, handling
11
12
  # the generation of site files.
13
+ #
12
14
  class Controller
13
15
 
14
16
  # New Controller.
17
+ #
18
+ # @param [Hash] options
19
+ # Controller options.
20
+ #
21
+ # @option options [String] :location
22
+ # Location of brite project.
23
+ #
24
+ # @option options [String] :output
25
+ # Redirect all output to this directory.
26
+ #
15
27
  def initialize(options={})
16
28
  @location = options[:location] || Dir.pwd
17
29
  @output = options[:output]
18
- @url = options[:url]
19
- @dryrun = options[:dryrun]
20
- @trace = options[:trace]
21
-
22
- @layouts = []
30
+ #@dryrun = options[:dryrun]
31
+ #@trace = options[:trace]
23
32
 
24
- initialize_site
25
- end
26
-
27
- # Returns an instance of Site.
28
- def initialize_site
29
- @site = Site.new(:url=>url)
30
-
31
- Dir.chdir(location) do
32
- files = Dir['**/*']
33
- files.each do |file|
34
- name = File.basename(file)
35
- ext = File.extname(file)
36
- case ext
37
- when '.layout'
38
- layouts << Layout.new(self, file)
39
- when '.page' #*%w{.markdown .rdoc .textile .whtml}
40
- @site.pages << initialize_page(file)
41
- when '.post'
42
- @site.posts << initialize_post(file)
43
- end
44
- end
45
- end
46
- @site.posts.sort!{ |a,b| b.date <=> a.date }
47
- @site
48
- end
49
-
50
- # Returns an instance of Page.
51
- #++
52
- # TODO: Limit Neapolitan to Markup formats only.
53
- #--
54
- def initialize_page(file)
55
- template = Neapolitan.file(file, :stencil=>config.stencil)
56
- settings = template.header
57
-
58
- settings[:site] = site
59
- settings[:file] = file
60
-
61
- Page.new(settings){ |page| render(template, page) }
62
- end
63
-
64
- # Returns an instance of Post.
65
- def initialize_post(file)
66
- template = Neapolitan.file(file, :stencil=>config.stencil)
67
- settings = template.header
68
-
69
- settings[:site] = site
70
- settings[:file] = file
71
-
72
- Post.new(settings){ |post| render(template, post) }
33
+ @site = Site.new(location, :url=>options[:url])
73
34
  end
74
35
 
75
36
  # Returns an instance of Site.
76
37
  attr :site
77
38
 
78
- #
39
+ # Directory of site files on disk.
79
40
  attr :location
80
41
 
81
- #
42
+ # Where to save results. Usually the templates are shadowed, which means
43
+ # the ouput is the same a location.
82
44
  attr :output
83
45
 
84
- # Is `dryrun` mode on?
85
- def dryrun?
86
- @dryrun
87
- end
88
-
89
- # Is `trace` mode on?
90
- def trace?
91
- @trace
92
- end
93
-
94
- # Returns an Array of Layouts.
95
- def layouts
96
- @layouts
97
- end
46
+ ## Returns an Array of Layouts.
47
+ #def layouts
48
+ # @site.layouts
49
+ #end
98
50
 
99
51
  # Access to configuration file data.
100
52
  def config
101
- @config ||= Config.new(location)
53
+ site.config
102
54
  end
103
55
 
104
56
  # URL of site as set in initializer or configuration file.
105
57
  def url
106
- @url ||= config.url
58
+ site.url
107
59
  end
108
60
 
109
- #
110
- def render(template, model) #scope=nil, &body)
111
- #if scope
112
- # scope.merge!(attributes)
113
- #else
114
- # scope = to_scope
115
- #end
116
-
117
- render = template.render(model) #, &body)
118
-
119
- model.summary = render.summary # TODO: make part of neapolitan?
120
-
121
- result = render.to_s
122
-
123
- if model.layout
124
- layout = lookup_layout(model.layout)
125
- raise "No such layout -- #{layout}" unless layout
126
- result = layout.render(model){ result }
127
- end
128
-
129
- result.to_s.strip
61
+ # Is `dryrun` mode on? Checks the global variable `$DRYRUN`.
62
+ def dryrun?
63
+ $DRYRUN #@dryrun
130
64
  end
131
65
 
132
- # Lookup layout by name.
133
- def lookup_layout(name)
134
- layouts.find{ |layout| name == layout.name }
66
+ # Is `trace` mode on? Checks global variable `$TRACE`.
67
+ def trace?
68
+ $TRACE #@trace
135
69
  end
136
70
 
137
- # Build site.
71
+ # Build the site.
138
72
  def build
139
73
  if trace?
140
- puts "Layouts: " + layouts.map{ |layout| layout.name }.join(", ")
141
- puts "Pages: " + pages.map{ |page| page.file }.join(", ")
142
- puts "Posts: " + posts.map{ |post| post.file }.join(", ")
74
+ puts "Layouts: " + site.layouts.map{ |layout| layout.name }.join(", ")
75
+ puts "Parts: " + site.parts.map{ |part| part.name }.join(", ")
76
+ puts "Pages: " + site.pages.map{ |page| page.file }.join(", ")
77
+ puts "Posts: " + site.posts.map{ |post| post.file }.join(", ")
143
78
  puts
144
79
  end
80
+
145
81
  Dir.chdir(location) do
146
82
  site.posts.each do |post|
83
+ puts "Rendering #{post.file}" if $DEBUG
147
84
  save(post)
148
85
  end
149
86
  site.pages.each do |page|
87
+ puts "Rendering #{page.file}" if $DEBUG
150
88
  save(page)
151
89
  end
152
90
  end
153
- puts "#{site.pages.size + site.posts.size} Files: #{site.pages.size} Pages, #{site.posts.size} Posts"
91
+ puts "\n#{site.pages.size + site.posts.size} Files: #{site.pages.size} Pages, #{site.posts.size} Posts"
154
92
  end
155
93
 
156
94
  # Save page/post redering to disk.
95
+ #
96
+ # @param [Model] model
97
+ # The {Page} or {Post} to save to disk.
98
+ #
157
99
  def save(model)
158
100
  file = output ? File.join(output, model.output) : model.output
159
101
  text = model.to_s
@@ -1,35 +1,49 @@
1
+ require 'brite/model'
2
+
1
3
  module Brite
2
4
 
3
5
  # Layout class
4
- class Layout
6
+ class Layout < Model
5
7
 
6
8
  #
7
- def initialize(controller, file)
8
- @controller = controller
9
- @file = file
10
- @name = file.chomp('.layout')
11
- @path = File.expand_path(file)
9
+ def initialize(site, file)
10
+ @site = site
11
+ @file = file
12
+
13
+ @name = file.chomp('.layout')
14
+ @path = File.expand_path(file)
12
15
  end
13
16
 
14
- attr :controller
17
+ #
18
+ attr :site
15
19
 
20
+ #
16
21
  attr :file
17
22
 
23
+ #
24
+ attr :name
25
+
26
+ #
18
27
  attr :path
19
28
 
20
- attr :name
29
+ # TODO: merge layout header ?
21
30
 
22
- # TODO: merge in layout header
31
+ # Render layout.
23
32
  def render(model, &content)
24
- template = Neapolitan.file(path, :stencil=>controller.config.stencil)
33
+ template = Neapolitan.file(path, :stencil=>site.config.stencil)
34
+
35
+ # update the model's metadata
36
+ #model.update(template.metadata)
25
37
 
26
38
  result = template.render(model, &content).to_s
27
39
 
28
- layout = template.header['layout']
40
+ layout_name = template.metadata['layout']
41
+
42
+ if layout_name
43
+ layout = site.lookup_layout(layout_name)
29
44
 
30
- if layout
31
- layout = controller.lookup_layout(layout)
32
45
  raise "No such layout -- #{layout}" unless layout
46
+
33
47
  result = layout.render(model){ result }
34
48
  end
35
49