plate 0.6.3 → 0.7.0.pre

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## Plate 0.7.0 (Unreleased)
2
+
3
+ * Added support for view partials
4
+ * Reload page layout when re-rendering a page
5
+
1
6
  ## Plate 0.6.3
2
7
 
3
8
  * Pass through current site to Sass::Engine options for use within Sass plugins
@@ -6,48 +11,48 @@
6
11
 
7
12
  * Gem dependency updates
8
13
  * Upgraded Twitter Bootstrap to v2.0.3
9
- * Sass and Less partial modifications reload parent file regardless of file location and nesting.
14
+ * Sass and Less partial modifications reload parent file regardless of file location and nesting
10
15
 
11
16
  ## Plate 0.6.1
12
17
 
13
- * Added basic support for asset partials with Sass and Less. When using watch mode, partials will reload any referencing files if they are modified.
18
+ * Added basic support for asset partials with Sass and Less. When using watch mode, partials will reload any referencing files if they are modified
14
19
 
15
20
  ## Plate 0.6.0
16
21
 
17
- * Meta data can be read from the config file and used to store common site data such as title, description, author, etc.
22
+ * Meta data can be read from the config file and used to store common site data such as title, description, author, etc
18
23
  * Modified new site generator to use meta data structure
19
24
  * Added RSS feed as part of new site generation
20
25
  * Added helper for making relative links absolute for use within RSS feeds
21
26
  * Documentation updates
22
- * Added a new DSL for callbacks and other extensions. Files within `./lib` will now be evaluated using the DSL instead of just being required.
27
+ * Added a new DSL for callbacks and other extensions. Files within `./lib` will now be evaluated using the DSL instead of just being required
23
28
  * Helpers have been moved to a separate directory in the site source root named `./helpers`.
24
- * Added new site template with some base CSS styles and helpful information to get started.
25
- * Allow a build destination to be set within the config.yml file.
29
+ * Added new site template with some base CSS styles and helpful information to get started
30
+ * Allow a build destination to be set within the config.yml file
26
31
  * Allow customization of Sass output style with config variable :sass_style
27
- * Added DSL methods to register asset and template engines.
28
- * Added engine for Less CSS processing. Install the less gem to use this engine.
32
+ * Added DSL methods to register asset and template engines
33
+ * Added engine for Less CSS processing. Install the less gem to use this engine
29
34
 
30
35
  ## Plate 0.5.4
31
36
 
32
- * Added config option to command line utility to load a specific config file.
33
- * Allowed new post command to have default options stored in config.yml file.
37
+ * Added config option to command line utility to load a specific config file
38
+ * Allowed new post command to have default options stored in config.yml file
34
39
 
35
40
  ## Plate 0.5.3
36
41
 
37
- * Added support for Sass @import statements.
38
- * Partial-style assets are not included in the build by default. Partial file names start with an underscore.
42
+ * Added support for Sass @import statements
43
+ * Partial-style assets are not included in the build by default. Partial file names start with an underscore
39
44
 
40
45
  ## Plate 0.5.2
41
46
 
42
- * Added `platify` command line utility to set up a new site.
47
+ * Added `platify` command line utility to set up a new site
43
48
 
44
49
  ## Plate 0.5.1
45
50
 
46
- * Updates to new post command line utility. Pass in a category and layout to a new post.
51
+ * Updates to new post command line utility (Pass in a category and layout to a new post)
47
52
 
48
53
  ## Plate 0.5.0
49
54
 
50
- * Initial build, basic site generation, asset compilation and template handling.
55
+ * Initial build, basic site generation, asset compilation and template handling
51
56
  * Command line interface
52
57
  * Rebuilding site with changes on demand with the `--watch` parameter
53
58
  * Basic callbacks for manipulating page and site content
data/README.md CHANGED
@@ -8,7 +8,7 @@ In addition to basic formatting with Markdown, Plate also supports generating mo
8
8
 
9
9
  Plate is a command line utility installed as a Ruby Gem. Installation requires Ruby 1.8.7, 1.9.2 or 1.9.3. For additional processing, install CoffeeScript, Sass, Haml and other formatters.
10
10
 
11
- Current version is **0.6.0**
11
+ Current version is **0.6.3**
12
12
 
13
13
  ## Installation
14
14
 
@@ -115,6 +115,10 @@ Then, in your `.erb` view you can call `sample_helper_method`.
115
115
 
116
116
  All files in the `helpers/` directory are assumed to be helper modules and will be loaded automatically at runtime.
117
117
 
118
+ ### Partials
119
+
120
+ **Coming Soon.**
121
+
118
122
  ## Full Documentation
119
123
 
120
124
  View the [full documentation on rdoc.info](http://rdoc.info/gems/plate/frames)
data/lib/plate.rb CHANGED
@@ -19,6 +19,7 @@ module Plate
19
19
 
20
20
  autoload :BloggingHelper, 'plate/helpers/blogging_helper'
21
21
  autoload :MetaHelper, 'plate/helpers/meta_helper'
22
+ autoload :PartialsHelper, 'plate/helpers/partials_helper'
22
23
  autoload :URLHelper, 'plate/helpers/url_helper'
23
24
 
24
25
  autoload :View, 'plate/view'
@@ -28,6 +29,7 @@ module Plate
28
29
 
29
30
  autoload :Asset, 'plate/asset'
30
31
  autoload :DynamicPage, 'plate/dynamic_page'
32
+ autoload :Partial, 'plate/partial'
31
33
  autoload :Page, 'plate/page'
32
34
  autoload :Post, 'plate/post'
33
35
  autoload :StaticPage, 'plate/static_page'
data/lib/plate/builder.rb CHANGED
@@ -235,16 +235,25 @@ module Plate
235
235
  else
236
236
  # Check for partials, and run any files that reference it.
237
237
  if File.basename(relative_file_path) =~ /^_/
238
- partial_name = File.basename(relative_file_path, '.*').gsub(/^_/, '')
239
-
240
238
  log("Partial modified. Reloading referencing files", :indent)
241
239
 
242
- other_files = site.find_by_extension(File.extname(relative_file_path))
240
+ name = Partial.name(site, relative_file_path.gsub(/^\/?content\//, ''))
241
+ partial = Partial.find(site, name)
243
242
 
244
- other_files.each do |file|
245
- if Array === file.partials
246
- if file.partials.include?(partial_name)
247
- self.render_file!(file.relative_file)
243
+ if partial
244
+ partial.reload!
245
+ partial.pages.each do |page|
246
+ self.render_file!(page.relative_file)
247
+ end
248
+ else
249
+ partial_name = File.basename(relative_file_path, '.*').gsub(/^_/, '')
250
+ other_files = site.find_by_extension(File.extname(relative_file_path))
251
+
252
+ other_files.each do |file|
253
+ if Array === file.partials
254
+ if file.partials.include?(partial_name)
255
+ self.render_file!(file.relative_file)
256
+ end
248
257
  end
249
258
  end
250
259
  end
@@ -0,0 +1,33 @@
1
+ module Plate
2
+ # Allow for partials within views
3
+ module PartialsHelper
4
+ def render(options = {}, locals = {})
5
+ path = options
6
+
7
+ # If a hash is passed as the first option, use it for locals
8
+ if Hash === options
9
+ path = options.delete(:partial)
10
+ locals = options.clone
11
+ end
12
+
13
+ locals.symbolize_keys!
14
+
15
+ render_partial(path.to_s, locals)
16
+ end
17
+
18
+ protected
19
+ # Create a new partial with the given options, and return its content
20
+ def render_partial(path, locals)
21
+ partial_name = Partial.name(self.site, path, self.file)
22
+ partial = Partial.find(self.site, partial_name)
23
+
24
+ if partial
25
+ self.page.partials << partial unless self.page.partials.include?(partial)
26
+ partial.pages << self.page unless partial.pages.include?(self.page)
27
+ partial.render(locals)
28
+ else
29
+ nil
30
+ end
31
+ end
32
+ end
33
+ end
@@ -27,7 +27,8 @@ module Plate
27
27
  :paths => paths
28
28
  })
29
29
 
30
- scope.partials = data.to_s.scan(/@import\s"(.*?)";/i).flatten.collect { |s| s.split('/').last.gsub(/^_/, '') }
30
+ partials = data.to_s.scan(/@import\s"(.*?)";/i).flatten.collect { |s| s.split('/').last.gsub(/^_/, '') }
31
+ scope.partials = scope.partials + partials
31
32
 
32
33
  parser = ::Less::Parser.new(less_options)
33
34
  parser.parse(data).to_css
data/lib/plate/page.rb CHANGED
@@ -17,6 +17,7 @@ module Plate
17
17
  self.file = file
18
18
  self.meta = {}
19
19
  self.content = ""
20
+ self.partials = []
20
21
 
21
22
  load! if load_on_initialize and file?
22
23
  end
@@ -135,7 +136,7 @@ module Plate
135
136
  # The layout to use when rendering this page. Returns nil if no default layout is available,
136
137
  # or the layout has specifically been turned off within the config.
137
138
  def layout
138
- return @layout if defined?(@layout)
139
+ return @layout if @layout
139
140
  self.layout = self.meta[:layout]
140
141
  @layout
141
142
  end
@@ -143,7 +144,7 @@ module Plate
143
144
  # Manually set the layout
144
145
  def layout=(value)
145
146
  if value == false
146
- @layout = nil
147
+ @layout = :none
147
148
  elsif value
148
149
  @layout = self.site.find_layout(value)
149
150
  else
@@ -178,12 +179,15 @@ module Plate
178
179
  end
179
180
 
180
181
  def reload!
182
+ self.meta = {}
183
+ self.partials = []
184
+ self.content = nil
185
+
181
186
  @loaded = false
182
- @content = nil
183
- @meta = {}
184
- @keywords = nil
185
187
  @rendered_content = nil
186
188
  @body = nil
189
+ @keywords = nil
190
+ @layout = nil
187
191
 
188
192
  load!
189
193
  end
@@ -0,0 +1,70 @@
1
+ module Plate
2
+ # A partial is a special type of page that is not rendered on its own, but is called
3
+ # within another page. Just like partials in Rails, or server-side includes in other
4
+ # packages.
5
+ class Partial < Page
6
+ # The locals hash provided to the current render of this partial.
7
+ # Locals are reset after each render
8
+ attr_reader :locals
9
+
10
+ # All pages that are using this partial, so they can be reloaded if the partial changes.
11
+ attr_accessor :pages
12
+
13
+ def initialize(site, file)
14
+ @pages = []
15
+ super(site, file)
16
+ end
17
+
18
+ # Partial names are the relative filename, without any extensions
19
+ def name
20
+ @name ||= Partial.name(self.site, self.file, self.site.source)
21
+ end
22
+
23
+ # The content for the current partial using the given locals hash
24
+ def render(locals = {})
25
+ @locals = locals.symbolize_keys!
26
+ result = self.rendered_body
27
+ @locals = nil
28
+ @locals_proxy = nil
29
+ @body = nil
30
+
31
+ result
32
+ end
33
+
34
+ # Allow calls to locals hash via the locals proxy
35
+ def method_missing(method, *args)
36
+ return super unless locals_proxy
37
+ locals_proxy.send(method, *args)
38
+ end
39
+
40
+ class << self
41
+ # Find a partial based on the given path and site
42
+ def find(site, name)
43
+ site.partials.find { |partial| partial.name == name }
44
+ end
45
+
46
+ # Convert a file path into a partial name
47
+ def name(site, file, reference = nil)
48
+ unless File.exists?(file)
49
+ if (file =~ /^\.\.?\// or !file.include?('/')) and !reference.nil?
50
+ file = File.expand_path(File.join(File.dirname(reference), file))
51
+ else
52
+ file = File.expand_path(File.join(site.source, 'content', file))
53
+ end
54
+ end
55
+
56
+ base = File.basename(file).gsub(/^_/, '').split('.').first
57
+ dir = site.relative_path(File.dirname(file))
58
+
59
+ "#{dir}/#{base}".gsub(/^\/?content\//, '')
60
+ end
61
+ end
62
+
63
+ protected
64
+ # Set up a hash proxy that allows method calls for keys
65
+ def locals_proxy
66
+ return nil unless locals
67
+ @locals_proxy ||= HashProxy.new(locals)
68
+ end
69
+ end
70
+ end
@@ -38,7 +38,8 @@ module Plate
38
38
  options[:cache_location] = File.join(scope.site.cache_location, 'sass-cache')
39
39
  end
40
40
 
41
- scope.partials = data.to_s.scan(/@import\s"(.*?)";/i).flatten.collect { |s| s.split('/').last }
41
+ partials = data.to_s.scan(/@import\s"(.*?)";/i).flatten.collect { |s| s.split('/').last }
42
+ scope.partials = scope.partials + partials
42
43
 
43
44
  ::Sass::Engine.new(data, options).render
44
45
  end
data/lib/plate/site.rb CHANGED
@@ -9,6 +9,9 @@ module Plate
9
9
  attr_accessor :assets, :build_destination, :cache_location, :destination,
10
10
  :layouts, :logger, :metadata, :options, :pages, :posts, :source
11
11
 
12
+ # An array of all view partials available in this site.
13
+ attr_accessor :partials
14
+
12
15
  def initialize(source, destination, options = {})
13
16
  # Setup source and destination for the site files
14
17
  self.source = source
@@ -53,6 +56,7 @@ module Plate
53
56
  self.layouts = []
54
57
  self.pages = []
55
58
  self.posts = PostCollection.new
59
+ self.partials = []
56
60
 
57
61
  @metadata = {}
58
62
  end
@@ -211,7 +215,7 @@ module Plate
211
215
 
212
216
  protected
213
217
  # Load all layouts from layouts/
214
- def load_layouts!(log = true)
218
+ def load_layouts!(verbose = true)
215
219
  @layouts = []
216
220
 
217
221
  Dir.glob(File.join(source, "layouts/**/*")).each do |file|
@@ -221,17 +225,21 @@ module Plate
221
225
  end
222
226
  end
223
227
 
224
- log("#{@layouts.size} layouts loaded") if log
228
+ log("#{@layouts.size} layouts loaded") if verbose
225
229
 
226
230
  @layouts
227
231
  end
228
232
 
229
- def load_pages!(log = true)
233
+ def load_pages!(verbose = true)
230
234
  @assets = []
231
235
  @pages = []
236
+ @partials = []
232
237
 
233
238
  # Load all pages, static pages and assets from content/
234
239
  Dir.glob(File.join(source, "content/**/*")).each do |file|
240
+ # Detect if this is a partial or not
241
+ partial = File.basename(file).start_with?('_')
242
+
235
243
  # If this 'file' is a directory, just skip it. We only care about files.
236
244
  unless File.directory?(file)
237
245
  # Check for assets that need to be compiled. Currently only looks to see if the file
@@ -239,31 +247,38 @@ module Plate
239
247
  #
240
248
  # Assets that start with _ are assumed to be partials and are not loaded.
241
249
  if asset_engine_extensions.include?(File.extname(file))
242
- unless File.basename(file).start_with?('_')
250
+ unless partial
243
251
  @assets << Asset.new(self, file)
244
252
  end
245
253
  else
246
- # Check for YAML meta header. If it starts with ---, then process it as a page
247
- intro = File.open(file) { |f| f.read(3) }
248
-
249
- # If file contents start with ---, then it is something we should process as a page.
250
- if intro == "---"
251
- @pages << Page.new(self, file)
254
+ if partial
255
+ @partials << Partial.new(self, file)
252
256
  else
253
- @pages << StaticPage.new(self, file)
257
+ # Check for YAML meta header. If it starts with ---, then process it as a page
258
+ intro = File.open(file) { |f| f.read(3) }
259
+
260
+ # If file contents start with ---, then it is something we should process as a page.
261
+ if intro == "---"
262
+ @pages << Page.new(self, file)
263
+ else
264
+ @pages << StaticPage.new(self, file)
265
+ end
254
266
  end
255
267
  end
256
268
  end
257
269
  end
258
270
 
259
- log("#{@assets.size} assets loaded") if log
260
- log("#{@pages.size} pages and other files loaded") if log
271
+ if verbose
272
+ log("#{@assets.size} assets loaded")
273
+ log("#{@pages.size} pages and other files loaded")
274
+ log("#{@partials.size} partials loaded")
275
+ end
261
276
 
262
277
  @pages
263
278
  end
264
279
 
265
280
  # Load blog posts from posts/
266
- def load_posts!(log = true)
281
+ def load_posts!(verbose = true)
267
282
  @posts = PostCollection.new
268
283
 
269
284
  Dir.glob(File.join(source, "posts/**/*")).each do |file|
@@ -281,7 +296,7 @@ module Plate
281
296
 
282
297
  @posts.sort!
283
298
 
284
- log("#{@posts.size} posts loaded") if log
299
+ log("#{@posts.size} posts loaded") if verbose
285
300
 
286
301
  @posts
287
302
  end
data/lib/plate/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Plate
2
- VERSION = "0.6.3" unless defined?(::Plate::VERSION)
2
+ VERSION = "0.7.0.pre" unless defined?(::Plate::VERSION)
3
3
  end
data/lib/plate/view.rb CHANGED
@@ -7,13 +7,14 @@ module Plate
7
7
  class View
8
8
  include BloggingHelper
9
9
  include MetaHelper
10
+ include PartialsHelper
10
11
  include URLHelper
11
12
 
12
13
  # @return [Page] The current page (or post) being rendered.
13
14
  attr_reader :page
14
15
 
15
16
  # @return [Site] The current site build.
16
- attr_reader :site, :page
17
+ attr_reader :site
17
18
 
18
19
  # Create a new view by passing in the current {Plate::Site site} and {Plate::Page page}
19
20
  # instance.
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
5
- prerelease:
4
+ version: 0.7.0.pre
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Tornow
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-16 00:00:00.000000000Z
12
+ date: 2012-07-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70119662223360 !ruby/object:Gem::Requirement
16
+ requirement: &70256245018440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70119662223360
24
+ version_requirements: *70256245018440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: directory_watcher
27
- requirement: &70119662222940 !ruby/object:Gem::Requirement
27
+ requirement: &70256245018040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70119662222940
35
+ version_requirements: *70256245018040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &70119662222400 !ruby/object:Gem::Requirement
38
+ requirement: &70256245017460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.6'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70119662222400
46
+ version_requirements: *70256245017460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70119662221980 !ruby/object:Gem::Requirement
49
+ requirement: &70256245017040 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70119662221980
57
+ version_requirements: *70256245017040
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: redcarpet
60
- requirement: &70119662221440 !ruby/object:Gem::Requirement
60
+ requirement: &70256245016500 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '2'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70119662221440
68
+ version_requirements: *70256245016500
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: tilt
71
- requirement: &70119662220920 !ruby/object:Gem::Requirement
71
+ requirement: &70256245016000 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '1.3'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70119662220920
79
+ version_requirements: *70256245016000
80
80
  description: Plate is a simple, static site generator and blog engine.
81
81
  email:
82
82
  - john@johntornow.com
@@ -100,11 +100,13 @@ files:
100
100
  - lib/plate/hash_proxy.rb
101
101
  - lib/plate/helpers/blogging_helper.rb
102
102
  - lib/plate/helpers/meta_helper.rb
103
+ - lib/plate/helpers/partials_helper.rb
103
104
  - lib/plate/helpers/url_helper.rb
104
105
  - lib/plate/layout.rb
105
106
  - lib/plate/less_template.rb
106
107
  - lib/plate/markdown_template.rb
107
108
  - lib/plate/page.rb
109
+ - lib/plate/partial.rb
108
110
  - lib/plate/post.rb
109
111
  - lib/plate/post_collection.rb
110
112
  - lib/plate/sass_template.rb