nanoc 1.2 → 1.3

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.
data/ChangeLog CHANGED
@@ -1,11 +1,24 @@
1
+ == 1.3
2
+
3
+ * The @pages array now also contains uncompiled pages
4
+ * Pages with 'skip_output' set to true will not be outputted
5
+ * Added new filters
6
+ * Textile/RedCloth
7
+ * Sass
8
+ * nanoc now warns before overwriting in create_site, create_page and
9
+ create_template (but not in compile)
10
+
1
11
  == 1.2
2
12
 
3
- * Sites now have an 'assets' directory, whose contents are copied to the 'output' directory when compiling
13
+ * Sites now have an 'assets' directory, whose contents are copied to the
14
+ 'output' directory when compiling
4
15
  * Added support for non-eRuby layouts (Markaby, Haml, Liquid, ...)
5
16
  * Added many more filters
6
17
  * Improved error reporting
7
- * Accessing page attributes using instance variables, and not through @page, is no longer possible
8
- * Page attributes can now be accessed using dot notation, i.e. @page.title as well as @page[:title]
18
+ * Accessing page attributes using instance variables, and not through @page,
19
+ is no longer possible
20
+ * Page attributes can now be accessed using dot notation, i.e. @page.title as
21
+ well as @page[:title]
9
22
 
10
23
  == 1.1.3
11
24
 
@@ -21,12 +34,14 @@
21
34
  * Added support for nested layouts
22
35
  * Added coloured logging
23
36
  * @page now hold the page that is currently being processed
24
- * Index files are now called “content” files and are now named after the directory they are in [Colin Barrett]
37
+ * Index files are now called “content” files and are now named after the
38
+ directory they are in [Colin Barrett]
25
39
  * It is now possible to access @page in the page’s content file
26
40
 
27
41
  == 1.0.1
28
42
 
29
- * Fixed a bug which would cause a “no such template” error to be displayed when the template existed but compiling it would raise an exception
43
+ * Fixed a bug which would cause a “no such template” error to be displayed
44
+ when the template existed but compiling it would raise an exception
30
45
  * Fixed bug which would cause pages not to be sorted by order before compiling
31
46
 
32
47
  == 1.0
data/lib/compiler.rb CHANGED
@@ -39,31 +39,23 @@ module Nanoc
39
39
 
40
40
  # Put pages in their layouts
41
41
  pages.each do |page|
42
- # Prepare layout content
43
- content = nil
44
- context = { :page => page.merge(:_content_filename => nil), :pages => pages }
45
- layout = layout_for_page(page)
42
+ # Skip pages that should not be outputed
43
+ next if page.skip_output
44
+
46
45
  begin
47
- case layout[:type]
48
- when :eruby
49
- content = layout[:content].eruby(context)
50
- when :haml
51
- content = layout[:content].haml(context)
52
- when :markaby
53
- content = layout[:content].markaby(context)
54
- when :liquid
55
- content = layout[:content].liquid(context)
56
- end
46
+ # Prepare layout content
47
+ content = layouted_page(page, pages)
48
+
49
+ # Write page with layout
50
+ FileManager.create_file(path_for_page(page)) { content }
57
51
  rescue => exception
58
- $stderr.puts "Exception occured while layouting page" +
52
+ $stderr.puts "Exception occured while layouting page " +
59
53
  "'#{page[:_content_filename]}' in layout '#{page[:layout]}':" unless $quiet
60
54
  $stderr.puts exception unless $quiet
61
55
  $stderr.puts exception.backtrace.join("\n") unless $quiet
62
56
  exit
63
57
  end
64
58
 
65
- # Write page with layout
66
- FileManager.create_file(path_for_page(page)) { content }
67
59
  end
68
60
  end
69
61
 
@@ -133,27 +125,61 @@ module Nanoc
133
125
 
134
126
  # Compiles the given pages and returns the compiled pages
135
127
  def compile_pages(a_pages)
136
- a_pages.inject([]) do |pages, page|
128
+ # Create page objects from given pages
129
+ given_pages = []
130
+ a_pages.each { |page| given_pages << Page.new(page) }
131
+
132
+ # Create arrays for two kinds of pages
133
+ compiled_pages = []
134
+ uncompiled_pages = []
135
+ given_pages.each { |page| uncompiled_pages << page }
136
+
137
+ # Compile all pages
138
+ given_pages.each do |page|
137
139
  # Read page
138
- content = File.read(page[:_content_filename])
140
+ content = File.read(page._content_filename)
139
141
 
140
- # Filter page
142
+ # Compile page
141
143
  begin
142
- content = content.filter(page[:filters], :assigns => { :page => Page.new(page), :pages => pages })
144
+ content = content.filter(page.filters, :assigns => { :page => page, :pages => uncompiled_pages + compiled_pages })
143
145
  rescue Exception => exception
144
- $stderr.puts "Exception occured while compiling page" +
146
+ $stderr.puts "Exception occured while compiling page " +
145
147
  "'#{page[:_content_filename]}':" unless $quiet
146
148
  $stderr.puts exception unless $quiet
147
149
  $stderr.puts exception.backtrace.join("\n") unless $quiet
148
150
  exit
149
151
  end
150
152
 
153
+ # Move from uncompiled to compiled
154
+ uncompiled_pages -= [ page ]
155
+ compiled_pages += [ page ]
156
+
151
157
  # Create compiled page
152
- compiled_page = page.merge( :content => content )
158
+ page[:content] = content
159
+ end
153
160
 
154
- # Remember page
155
- pages + [ Page.new(compiled_page) ]
161
+ # Return all pages
162
+ compiled_pages
163
+ end
164
+
165
+ # Layouts the page
166
+ def layouted_page(a_page, a_pages)
167
+ context = { :page => a_page.merge(:_content_filename => nil), :pages => a_pages }
168
+ layout = layout_for_page(a_page)
169
+
170
+ content = nil
171
+ case layout[:type]
172
+ when :eruby
173
+ content = layout[:content].eruby(context)
174
+ when :haml
175
+ content = layout[:content].haml(context)
176
+ when :markaby
177
+ content = layout[:content].markaby(context)
178
+ when :liquid
179
+ content = layout[:content].liquid(context)
156
180
  end
181
+
182
+ content
157
183
  end
158
184
 
159
185
  end
data/lib/creator.rb CHANGED
@@ -3,6 +3,13 @@ module Nanoc
3
3
  class Creator
4
4
 
5
5
  def self.create_site(a_sitename)
6
+ # Make sure we're not accidentally overwriting anything
7
+ if File.exist?(a_sitename)
8
+ $stderr.puts 'ERROR: A file or directory named ' + a_sitename +
9
+ ' already exists.' unless $quiet
10
+ exit
11
+ end
12
+
6
13
  FileManager.create_dir a_sitename do
7
14
  FileManager.create_dir 'assets'
8
15
  FileManager.create_dir 'output'
@@ -96,6 +103,13 @@ module Nanoc
96
103
  def self.create_page(a_pagename, a_params={})
97
104
  Nanoc.ensure_in_site
98
105
 
106
+ # Make sure we're not accidentally overwriting anything
107
+ if File.exist?(File.join(['content', a_pagename]))
108
+ $stderr.puts 'ERROR: A file or directory named ' + a_pagename +
109
+ ' already exists.' unless $quiet
110
+ exit
111
+ end
112
+
99
113
  # Sanitize page name
100
114
  if a_pagename =~ /^[\/\.]+/
101
115
  $stderr.puts 'ERROR: page name starts with dots and/or slashes, aborting' unless $quiet == true
@@ -136,6 +150,13 @@ module Nanoc
136
150
  def self.create_template(a_templatename)
137
151
  Nanoc.ensure_in_site
138
152
 
153
+ # Make sure we're not accidentally overwriting anything
154
+ if File.exist?(File.join(['templates', a_templatename]))
155
+ $stderr.puts 'ERROR: A file or directory named ' + a_templatename +
156
+ ' already exists.' unless $quiet
157
+ exit
158
+ end
159
+
139
160
  FileManager.create_dir 'templates' do
140
161
  FileManager.create_dir a_templatename do
141
162
  FileManager.create_file "#{a_templatename}.txt" do
data/lib/enhancements.rb CHANGED
@@ -7,6 +7,7 @@ require 'fileutils'
7
7
  require 'yaml'
8
8
 
9
9
  try_require 'bluecloth'
10
+ try_require 'redcloth'
10
11
  try_require 'rubypants'
11
12
  try_require 'markaby'
12
13
  try_require 'liquid'
@@ -75,12 +76,16 @@ class String
75
76
  result.replace(result.liquid(a_params[:assigns]))
76
77
  when 'markaby'
77
78
  result.replace(result.markaby(a_params[:assigns]))
78
- when 'markdown'
79
+ when 'markdown', 'bluecloth'
79
80
  result.replace(result.markdown)
80
81
  when 'rdoc'
81
82
  result.replace(result.rdoc)
82
- when 'smartypants'
83
+ when 'sass'
84
+ result.replace(result.sass)
85
+ when 'smartypants', 'rubypants'
83
86
  result.replace(result.smartypants)
87
+ when 'textile', 'redcloth'
88
+ result.replace(result.textile)
84
89
  end
85
90
  end
86
91
  end
@@ -128,6 +133,11 @@ class String
128
133
  SM::SimpleMarkup.new.convert(self, SM::ToHtml.new)
129
134
  end
130
135
 
136
+ # Converts the string using Sass
137
+ def sass
138
+ Sass::Engine.new(self).render
139
+ end
140
+
131
141
  # Converts the string using RedCloth/Textile
132
142
  def textile
133
143
  RedCloth.new(self).to_html
data/lib/nanoc.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Nanoc
2
- VERSION = '1.2'
2
+ VERSION = '1.3'
3
3
 
4
4
  def self.ensure_in_site
5
5
  unless in_site?
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: nanoc
5
5
  version: !ruby/object:Gem::Version
6
- version: "1.2"
7
- date: 2007-06-05 00:00:00 +02:00
6
+ version: "1.3"
7
+ date: 2007-06-24 00:00:00 +02:00
8
8
  summary: a CMS that doesn't run on your server
9
9
  require_paths:
10
10
  - lib