nanoc 1.6.2 → 2.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 (51) hide show
  1. data/ChangeLog +27 -0
  2. data/Rakefile +34 -27
  3. data/bin/nanoc +153 -49
  4. data/lib/nanoc.rb +15 -33
  5. data/lib/nanoc/base/auto_compiler.rb +124 -0
  6. data/lib/nanoc/base/compiler.rb +55 -0
  7. data/lib/nanoc/base/core_ext/hash.rb +34 -0
  8. data/lib/nanoc/base/data_source.rb +53 -0
  9. data/lib/nanoc/base/enhancements.rb +89 -0
  10. data/lib/nanoc/base/filter.rb +16 -0
  11. data/lib/nanoc/base/layout_processor.rb +33 -0
  12. data/lib/nanoc/base/page.rb +155 -0
  13. data/lib/nanoc/base/page_proxy.rb +31 -0
  14. data/lib/nanoc/base/plugin.rb +19 -0
  15. data/lib/nanoc/base/plugin_manager.rb +33 -0
  16. data/lib/nanoc/base/site.rb +143 -0
  17. data/lib/nanoc/data_sources/database.rb +259 -0
  18. data/lib/nanoc/data_sources/filesystem.rb +308 -0
  19. data/lib/nanoc/data_sources/trivial.rb +145 -0
  20. data/lib/nanoc/filters/erb.rb +34 -0
  21. data/lib/nanoc/filters/haml.rb +16 -0
  22. data/lib/nanoc/filters/markaby.rb +15 -0
  23. data/lib/nanoc/filters/markdown.rb +13 -0
  24. data/lib/nanoc/filters/rdoc.rb +14 -0
  25. data/lib/nanoc/filters/smartypants.rb +13 -0
  26. data/lib/nanoc/filters/textile.rb +13 -0
  27. data/lib/nanoc/layout_processors/erb.rb +35 -0
  28. data/lib/nanoc/layout_processors/haml.rb +18 -0
  29. data/lib/nanoc/layout_processors/markaby.rb +16 -0
  30. metadata +37 -30
  31. data/lib/nanoc/compiler.rb +0 -145
  32. data/lib/nanoc/core_ext.rb +0 -1
  33. data/lib/nanoc/core_ext/array.rb +0 -17
  34. data/lib/nanoc/core_ext/hash.rb +0 -43
  35. data/lib/nanoc/core_ext/string.rb +0 -13
  36. data/lib/nanoc/core_ext/yaml.rb +0 -10
  37. data/lib/nanoc/creator.rb +0 -180
  38. data/lib/nanoc/enhancements.rb +0 -101
  39. data/lib/nanoc/filters.rb +0 -7
  40. data/lib/nanoc/filters/eruby_filter.rb +0 -39
  41. data/lib/nanoc/filters/haml_filter.rb +0 -18
  42. data/lib/nanoc/filters/liquid_filter.rb +0 -47
  43. data/lib/nanoc/filters/markaby_filter.rb +0 -15
  44. data/lib/nanoc/filters/markdown_filter.rb +0 -13
  45. data/lib/nanoc/filters/rdoc_filter.rb +0 -15
  46. data/lib/nanoc/filters/sass_filter.rb +0 -13
  47. data/lib/nanoc/filters/smartypants_filter.rb +0 -13
  48. data/lib/nanoc/filters/textile_filter.rb +0 -13
  49. data/lib/nanoc/page.rb +0 -171
  50. data/lib/nanoc/page_drop.rb +0 -18
  51. data/lib/nanoc/page_proxy.rb +0 -30
@@ -1,15 +0,0 @@
1
- class String
2
-
3
- # Converts the string using Markaby
4
- # TODO perhaps add support for helpers
5
- def markaby(params={})
6
- nanoc_require 'markaby'
7
- Markaby::Builder.new((params[:assigns] || {})).instance_eval(self).to_s
8
- end
9
-
10
- end
11
-
12
- register_filter 'markaby' do |page, pages, config|
13
- assigns = { :page => page, :pages => pages }
14
- page.content.markaby(:assigns => assigns)
15
- end
@@ -1,13 +0,0 @@
1
- class String
2
-
3
- # Converts the string using Markdown
4
- def markdown
5
- nanoc_require 'bluecloth'
6
- BlueCloth.new(self).to_html
7
- end
8
-
9
- end
10
-
11
- register_filter 'markdown', 'bluecloth' do |page, pages, config|
12
- page.content.markdown
13
- end
@@ -1,15 +0,0 @@
1
- class String
2
-
3
- # Converts the string using RDoc
4
- def rdoc
5
- nanoc_require 'rdoc/markup/simple_markup'
6
- nanoc_require 'rdoc/markup/simple_markup/to_html'
7
-
8
- SM::SimpleMarkup.new.convert(self, SM::ToHtml.new)
9
- end
10
-
11
- end
12
-
13
- register_filter 'rdoc' do |page, pages, config|
14
- page.content.rdoc
15
- end
@@ -1,13 +0,0 @@
1
- class String
2
-
3
- # Converts the string using Sass
4
- def sass
5
- nanoc_require 'haml'
6
- Sass::Engine.new(self).render
7
- end
8
-
9
- end
10
-
11
- register_filter 'sass' do |page, pages, config|
12
- page.content.sass
13
- end
@@ -1,13 +0,0 @@
1
- class String
2
-
3
- # Converts the string using RubyPants/SmartyPants
4
- def smartypants
5
- nanoc_require 'rubypants'
6
- RubyPants.new(self).to_html
7
- end
8
-
9
- end
10
-
11
- register_filter 'smartypants', 'rubypants' do |page, pages, config|
12
- page.content.smartypants
13
- end
@@ -1,13 +0,0 @@
1
- class String
2
-
3
- # Converts the string using RedCloth/Textile
4
- def textile
5
- nanoc_require 'redcloth'
6
- RedCloth.new(self).to_html
7
- end
8
-
9
- end
10
-
11
- register_filter 'textile', 'redcloth' do |page, pages, config|
12
- page.content.textile
13
- end
@@ -1,171 +0,0 @@
1
- module Nanoc
2
-
3
- class Page
4
-
5
- attr_accessor :stage, :is_filtered, :content_filename
6
-
7
- def initialize(hash, compiler)
8
- @attributes = hash
9
- @compiler = compiler
10
- @stage = nil
11
- end
12
-
13
- def attributes
14
- @attributes
15
- end
16
-
17
- def content
18
- filter!
19
- @attributes[:content]
20
- end
21
-
22
- # Proxy/Liquid support
23
-
24
- def to_proxy(params={})
25
- PageProxy.new(self, :filter => params[:filter])
26
- end
27
-
28
- def to_liquid
29
- nanoc_require 'liquid'
30
- PageDrop.new(self)
31
- end
32
-
33
- # Helper methods
34
-
35
- def path
36
- if @attributes[:custom_path].nil?
37
- @compiler.config[:output_dir] + @attributes[:path] +
38
- @attributes[:filename] + '.' + @attributes[:extension]
39
- else
40
- @compiler.config[:output_dir] + @attributes[:custom_path]
41
- end
42
- end
43
-
44
- def file
45
- File.new(@content_filename)
46
- end
47
-
48
- def find_layout
49
- if @attributes[:layout].nil?
50
- { :type => :eruby, :content => "<%= @page.content %>" }
51
- else
52
- # Find all layouts
53
- filenames = Dir["layouts/#{@attributes[:layout]}.*"]
54
-
55
- # Reject backups
56
- filenames.reject! { |f| f =~ /~$/ }
57
-
58
- # Make sure there is only one content file
59
- filenames.ensure_single('layout files', @attributes[:layout])
60
-
61
- # Get the first (and only one)
62
- filename = filenames[0]
63
-
64
- { :type => Nanoc::Compiler::FILE_TYPES[File.extname(filename)], :content => File.read(filename) }
65
- end
66
- end
67
-
68
- # Filtering
69
-
70
- def filter!
71
- # Get stack and list of other pages
72
- stack = @compiler.stack
73
- other_pages = @compiler.pages
74
-
75
- # Check for recursive call
76
- if stack.include?(self)
77
- # Print stack
78
- unless $quiet
79
- $stderr.puts 'ERROR: Recursive call to page content.'
80
- print_stack
81
- end
82
-
83
- exit
84
- end
85
-
86
- # Get filters
87
- if @stage == :pre
88
- filters = @attributes[:filters_pre] || @attributes[:filters] || []
89
- elsif @stage == :post
90
- filters = @attributes[:filters_post] || []
91
- end
92
-
93
- # Filter if not yet filtered
94
- unless @is_filtered
95
- stack.pushing(self) do
96
- # Read page
97
- content = @attributes[:content] || File.read(@content_filename)
98
-
99
- begin
100
- # Get params
101
- page = self.to_proxy(:filter => false)
102
- pages = other_pages.map { |p| p.to_proxy }
103
- config = $nanoc_compiler.config
104
-
105
- # Filter page
106
- @attributes[:content] = content
107
- filters.each do |filter_name|
108
- filter = $nanoc_compiler.filter_named(filter_name)
109
- if filter.nil?
110
- $stderr.puts 'WARNING: Unknown filter: ' + filter_name unless $quiet
111
- else
112
- @attributes[:content] = filter.call(page, pages, config)
113
- @is_filtered = true
114
- end
115
- end
116
- rescue Exception => exception
117
- handle_exception(exception, "filter page '#{@content_filename}'")
118
- end
119
- end
120
- end
121
- end
122
-
123
- def layout!
124
- # Get list of other pages
125
- other_pages = @compiler.pages
126
-
127
- # Find layout
128
- layout = self.find_layout
129
-
130
- # Build params
131
- if layout[:type] == :liquid
132
- public_page = self.to_liquid
133
- public_pages = other_pages.map { |p| p.to_liquid }
134
- else
135
- public_page = self.to_proxy
136
- public_pages = other_pages.map { |p| p.to_proxy }
137
- end
138
- params = { :assigns => { :page => public_page, :pages => public_pages } }
139
- params[:haml_options] = (@attributes[:haml_options] || {}).symbolize_keys
140
-
141
- # Layout
142
- case layout[:type]
143
- when :eruby
144
- @attributes[:content] = layout[:content].eruby(params)
145
- when :haml
146
- @attributes[:content] = layout[:content].haml(params)
147
- when :markaby
148
- @attributes[:content] = layout[:content].markaby(params)
149
- when :liquid
150
- @attributes[:content] = layout[:content].liquid(params)
151
- else
152
- @attributes[:content] = nil
153
- end
154
- end
155
-
156
- def print_stack
157
- # Determine relevant part of stack
158
- stack_begin = @compiler.stack.index(self)
159
- stack_end = @compiler.stack.size
160
- relevant_stack_part = @compiler.stack.last(stack_end - stack_begin)
161
-
162
- # Print relevant part of stack
163
- $stderr.puts 'Page filter stack:'
164
- relevant_stack_part.each_with_index do |page, i|
165
- $stderr.puts "#{i} #{page.content_filename}"
166
- end
167
- end
168
-
169
- end
170
-
171
- end
@@ -1,18 +0,0 @@
1
- try_require 'liquid'
2
-
3
- module Nanoc
4
-
5
- begin
6
- class PageDrop < ::Liquid::Drop
7
- def initialize(page)
8
- @page = page
9
- end
10
-
11
- def before_method(name)
12
- name == 'content' ? @page.content : @page.attributes[name.to_sym]
13
- end
14
- end
15
- rescue NameError
16
- end
17
-
18
- end
@@ -1,30 +0,0 @@
1
- module Nanoc
2
- class PageProxy
3
-
4
- def initialize(page, params={})
5
- @page = page
6
- @do_filter = (params[:filter] != false)
7
- end
8
-
9
- def [](key)
10
- if key.to_sym == :content and @do_filter
11
- @page.content
12
- elsif key.to_sym == :file
13
- @page.file
14
- elsif key.to_s.ends_with?('?')
15
- @page.attributes[key.to_s[0..-2].to_sym]
16
- else
17
- @page.attributes[key]
18
- end
19
- end
20
-
21
- def []=(key, value)
22
- @page.attributes[key.to_sym] = value
23
- end
24
-
25
- def method_missing(method, *args)
26
- self[method]
27
- end
28
-
29
- end
30
- end