nanoc2 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/ChangeLog +3 -0
  2. data/LICENSE +19 -0
  3. data/README +75 -0
  4. data/Rakefile +76 -0
  5. data/bin/nanoc2 +26 -0
  6. data/lib/nanoc2.rb +73 -0
  7. data/lib/nanoc2/base.rb +26 -0
  8. data/lib/nanoc2/base/asset.rb +117 -0
  9. data/lib/nanoc2/base/asset_defaults.rb +21 -0
  10. data/lib/nanoc2/base/asset_rep.rb +282 -0
  11. data/lib/nanoc2/base/binary_filter.rb +44 -0
  12. data/lib/nanoc2/base/code.rb +41 -0
  13. data/lib/nanoc2/base/compiler.rb +67 -0
  14. data/lib/nanoc2/base/core_ext.rb +2 -0
  15. data/lib/nanoc2/base/core_ext/hash.rb +78 -0
  16. data/lib/nanoc2/base/core_ext/string.rb +8 -0
  17. data/lib/nanoc2/base/data_source.rb +286 -0
  18. data/lib/nanoc2/base/defaults.rb +30 -0
  19. data/lib/nanoc2/base/filter.rb +93 -0
  20. data/lib/nanoc2/base/layout.rb +91 -0
  21. data/lib/nanoc2/base/notification_center.rb +66 -0
  22. data/lib/nanoc2/base/page.rb +132 -0
  23. data/lib/nanoc2/base/page_defaults.rb +20 -0
  24. data/lib/nanoc2/base/page_rep.rb +324 -0
  25. data/lib/nanoc2/base/plugin.rb +71 -0
  26. data/lib/nanoc2/base/proxies.rb +5 -0
  27. data/lib/nanoc2/base/proxies/asset_proxy.rb +29 -0
  28. data/lib/nanoc2/base/proxies/asset_rep_proxy.rb +26 -0
  29. data/lib/nanoc2/base/proxies/layout_proxy.rb +25 -0
  30. data/lib/nanoc2/base/proxies/page_proxy.rb +35 -0
  31. data/lib/nanoc2/base/proxies/page_rep_proxy.rb +28 -0
  32. data/lib/nanoc2/base/proxy.rb +37 -0
  33. data/lib/nanoc2/base/router.rb +72 -0
  34. data/lib/nanoc2/base/site.rb +274 -0
  35. data/lib/nanoc2/base/template.rb +64 -0
  36. data/lib/nanoc2/binary_filters.rb +1 -0
  37. data/lib/nanoc2/binary_filters/image_science_thumbnail.rb +28 -0
  38. data/lib/nanoc2/cli.rb +9 -0
  39. data/lib/nanoc2/cli/base.rb +132 -0
  40. data/lib/nanoc2/cli/commands.rb +10 -0
  41. data/lib/nanoc2/cli/commands/autocompile.rb +80 -0
  42. data/lib/nanoc2/cli/commands/compile.rb +312 -0
  43. data/lib/nanoc2/cli/commands/create_layout.rb +85 -0
  44. data/lib/nanoc2/cli/commands/create_page.rb +85 -0
  45. data/lib/nanoc2/cli/commands/create_site.rb +323 -0
  46. data/lib/nanoc2/cli/commands/create_template.rb +76 -0
  47. data/lib/nanoc2/cli/commands/help.rb +69 -0
  48. data/lib/nanoc2/cli/commands/info.rb +125 -0
  49. data/lib/nanoc2/cli/commands/switch.rb +141 -0
  50. data/lib/nanoc2/cli/commands/update.rb +91 -0
  51. data/lib/nanoc2/cli/logger.rb +72 -0
  52. data/lib/nanoc2/data_sources.rb +2 -0
  53. data/lib/nanoc2/data_sources/filesystem.rb +707 -0
  54. data/lib/nanoc2/data_sources/filesystem_combined.rb +495 -0
  55. data/lib/nanoc2/extra.rb +6 -0
  56. data/lib/nanoc2/extra/auto_compiler.rb +285 -0
  57. data/lib/nanoc2/extra/context.rb +22 -0
  58. data/lib/nanoc2/extra/core_ext.rb +2 -0
  59. data/lib/nanoc2/extra/core_ext/hash.rb +54 -0
  60. data/lib/nanoc2/extra/core_ext/time.rb +13 -0
  61. data/lib/nanoc2/extra/file_proxy.rb +29 -0
  62. data/lib/nanoc2/extra/vcs.rb +48 -0
  63. data/lib/nanoc2/extra/vcses.rb +5 -0
  64. data/lib/nanoc2/extra/vcses/bazaar.rb +21 -0
  65. data/lib/nanoc2/extra/vcses/dummy.rb +20 -0
  66. data/lib/nanoc2/extra/vcses/git.rb +21 -0
  67. data/lib/nanoc2/extra/vcses/mercurial.rb +21 -0
  68. data/lib/nanoc2/extra/vcses/subversion.rb +21 -0
  69. data/lib/nanoc2/filters.rb +16 -0
  70. data/lib/nanoc2/filters/bluecloth.rb +13 -0
  71. data/lib/nanoc2/filters/erb.rb +19 -0
  72. data/lib/nanoc2/filters/erubis.rb +14 -0
  73. data/lib/nanoc2/filters/haml.rb +21 -0
  74. data/lib/nanoc2/filters/markaby.rb +14 -0
  75. data/lib/nanoc2/filters/maruku.rb +14 -0
  76. data/lib/nanoc2/filters/old.rb +19 -0
  77. data/lib/nanoc2/filters/rainpress.rb +13 -0
  78. data/lib/nanoc2/filters/rdiscount.rb +13 -0
  79. data/lib/nanoc2/filters/rdoc.rb +23 -0
  80. data/lib/nanoc2/filters/redcloth.rb +14 -0
  81. data/lib/nanoc2/filters/relativize_paths.rb +16 -0
  82. data/lib/nanoc2/filters/relativize_paths_in_css.rb +16 -0
  83. data/lib/nanoc2/filters/relativize_paths_in_html.rb +16 -0
  84. data/lib/nanoc2/filters/rubypants.rb +14 -0
  85. data/lib/nanoc2/filters/sass.rb +18 -0
  86. data/lib/nanoc2/helpers.rb +9 -0
  87. data/lib/nanoc2/helpers/blogging.rb +217 -0
  88. data/lib/nanoc2/helpers/capturing.rb +63 -0
  89. data/lib/nanoc2/helpers/filtering.rb +54 -0
  90. data/lib/nanoc2/helpers/html_escape.rb +25 -0
  91. data/lib/nanoc2/helpers/link_to.rb +113 -0
  92. data/lib/nanoc2/helpers/render.rb +49 -0
  93. data/lib/nanoc2/helpers/tagging.rb +56 -0
  94. data/lib/nanoc2/helpers/text.rb +38 -0
  95. data/lib/nanoc2/helpers/xml_sitemap.rb +63 -0
  96. data/lib/nanoc2/routers.rb +3 -0
  97. data/lib/nanoc2/routers/default.rb +54 -0
  98. data/lib/nanoc2/routers/no_dirs.rb +66 -0
  99. data/lib/nanoc2/routers/versioned.rb +79 -0
  100. metadata +185 -0
@@ -0,0 +1,85 @@
1
+ module Nanoc2::CLI
2
+
3
+ class CreateLayoutCommand < Cri::Command # :nodoc:
4
+
5
+ def name
6
+ 'create_layout'
7
+ end
8
+
9
+ def aliases
10
+ [ 'cl' ]
11
+ end
12
+
13
+ def short_desc
14
+ 'create a layout'
15
+ end
16
+
17
+ def long_desc
18
+ 'Create a new layout in the current site.'
19
+ end
20
+
21
+ def usage
22
+ "nanoc2 create_layout [path]"
23
+ end
24
+
25
+ def option_definitions
26
+ [
27
+ # --vcs
28
+ {
29
+ :long => 'vcs', :short => 'c', :argument => :required,
30
+ :desc => 'select the VCS to use'
31
+ }
32
+ ]
33
+ end
34
+
35
+ def run(options, arguments)
36
+ # Check arguments
37
+ if arguments.length != 1
38
+ $stderr.puts "usage: #{usage}"
39
+ exit 1
40
+ end
41
+
42
+ # Extract arguments
43
+ path = arguments[0].cleaned_path
44
+
45
+ # Make sure we are in a nanoc site directory
46
+ @base.require_site
47
+
48
+ # Set VCS if possible
49
+ @base.set_vcs(options[:vcs])
50
+
51
+ # Check whether layout is unique
52
+ if !@base.site.layouts.find { |l| l.path == path }.nil?
53
+ $stderr.puts "A layout already exists at #{path}. Please pick a unique name " +
54
+ "for the layout you are creating."
55
+ exit 1
56
+ end
57
+
58
+ # Setup notifications
59
+ Nanoc2::NotificationCenter.on(:file_created) do |file_path|
60
+ Nanoc2::CLI::Logger.instance.file(:high, :create, file_path)
61
+ end
62
+
63
+ # Create layout
64
+ layout = Nanoc2::Layout.new(
65
+ "<html>\n" +
66
+ " <head>\n" +
67
+ " <title><%= @page.title %></title>\n" +
68
+ " </head>\n" +
69
+ " <body>\n" +
70
+ " <p>Hi, I'm a new layout. Please customize me!</p>\n" +
71
+ "<%= @page.content %>\n" +
72
+ " </body>\n" +
73
+ "</html>\n",
74
+ { :filter => 'erb' },
75
+ path
76
+ )
77
+ layout.site = @base.site
78
+ layout.save
79
+
80
+ puts "A layout has been created at #{path}."
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,85 @@
1
+ module Nanoc2::CLI
2
+
3
+ class CreatePageCommand < Cri::Command # :nodoc:
4
+
5
+ def name
6
+ 'create_page'
7
+ end
8
+
9
+ def aliases
10
+ [ 'cp' ]
11
+ end
12
+
13
+ def short_desc
14
+ 'create a page'
15
+ end
16
+
17
+ def long_desc
18
+ 'Create a new page in the current site. The template that will be ' +
19
+ 'used for generating the page will be \'default\', unless otherwise ' +
20
+ 'specified.'
21
+ end
22
+
23
+ def usage
24
+ "nanoc2 create_page [options] [path]"
25
+ end
26
+
27
+ def option_definitions
28
+ [
29
+ # --vcs
30
+ {
31
+ :long => 'vcs', :short => 'c', :argument => :required,
32
+ :desc => 'select the VCS to use'
33
+ },
34
+ # --template
35
+ {
36
+ :long => 'template', :short => 't', :argument => :required,
37
+ :desc => 'specify the template for the new page'
38
+ }
39
+ ]
40
+ end
41
+
42
+ def run(options, arguments)
43
+ # Check arguments
44
+ if arguments.length != 1
45
+ $stderr.puts "usage: #{usage}"
46
+ exit 1
47
+ end
48
+
49
+ # Extract arguments and options
50
+ path = arguments[0].cleaned_path
51
+ template_name = options[:template] || 'default'
52
+
53
+ # Make sure we are in a nanoc site directory
54
+ @base.require_site
55
+
56
+ # Set VCS if possible
57
+ @base.set_vcs(options[:vcs])
58
+
59
+ # Find template
60
+ template = @base.site.templates.find { |t| t.name == template_name }
61
+ if template.nil?
62
+ $stderr.puts "A template named '#{template_name}' was not found; aborting."
63
+ exit 1
64
+ end
65
+
66
+ # Setup notifications
67
+ Nanoc2::NotificationCenter.on(:file_created) do |file_path|
68
+ Nanoc2::CLI::Logger.instance.file(:high, :create, file_path)
69
+ end
70
+
71
+ # Create page
72
+ page = Nanoc2::Page.new(
73
+ template.page_content,
74
+ template.page_attributes,
75
+ path
76
+ )
77
+ page.site = @base.site
78
+ page.save
79
+
80
+ puts "A page has been created at #{path}."
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,323 @@
1
+ module Nanoc2::CLI
2
+
3
+ class CreateSiteCommand < Cri::Command # :nodoc:
4
+
5
+ DEFAULT_PAGE = <<EOS
6
+ <h1>A Brand New nanoc Site</h1>
7
+ <p>You&#8217;ve just created a new nanoc site. The page you are looking at right now is the home page for your site (and it&#8217;s probably the only page).</p>
8
+ <p>To get started, consider replacing this default homepage with your own customized homepage. Some pointers on how to do so:</p>
9
+ <ul>
10
+ <li><strong>Change this page&#8217;s content</strong> by editing &#8220;content.txt&#8221; file in the &#8220;content&#8221; directory. This is the actual page content, and therefore doesn&#8217;t include the header, sidebar or style information (those are part of the layout).</li>
11
+ <li><strong>Change the layout</strong>, which is the &#8220;default.txt&#8221; file in the &#8220;layouts/default&#8221; directory, and create something unique (and hopefully less bland).</li>
12
+ </ul>
13
+ <p>If you need any help with customizing your nanoc web site, be sure to check out the documentation (see sidebar), and be sure to subscribe to the discussion group (also see sidebar). Enjoy!</p>
14
+ EOS
15
+
16
+ DEFAULT_LAYOUT = <<EOS
17
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
18
+ <html>
19
+ <head>
20
+ <title>A Brand New nanoc Site - <%= @page.title %></title>
21
+ <style type="text/css" media="screen">
22
+ * {
23
+ margin: 0;
24
+ padding: 0;
25
+
26
+ font-family: Georgia, Palatino, Times, 'Times New Roman', sans-serif;
27
+ }
28
+
29
+ body {
30
+ background: #fff;
31
+ }
32
+
33
+ a {
34
+ text-decoration: none;
35
+ }
36
+
37
+ a:link,
38
+ a:visited {
39
+ color: #f30;
40
+ }
41
+
42
+ a:hover {
43
+ color: #f90;
44
+ }
45
+
46
+ #main {
47
+ position: absolute;
48
+
49
+ top: 20px;
50
+ left: 280px;
51
+
52
+ width: 500px;
53
+ }
54
+
55
+ #main h1 {
56
+ font-size: 40px;
57
+ font-weight: normal;
58
+
59
+ line-height: 40px;
60
+
61
+ padding: 20px 0 20px 0;
62
+
63
+ letter-spacing: -1px;
64
+ }
65
+
66
+ #main p {
67
+ margin: 0 0 20px 0;
68
+
69
+ font-size: 15px;
70
+
71
+ line-height: 20px;
72
+ }
73
+
74
+ #main ul {
75
+ padding: 0 0 0 20px;
76
+ }
77
+
78
+ #main li {
79
+ margin: 0 0 20px 0;
80
+
81
+ list-style-type: square;
82
+
83
+ font-size: 15px;
84
+
85
+ line-height: 20px;
86
+ }
87
+
88
+ #sidebar {
89
+ position: absolute;
90
+
91
+ top: 40px;
92
+ left: 20px;
93
+ width: 200px;
94
+
95
+ padding: 20px 20px 0 0;
96
+
97
+ border-right: 1px solid #ccc;
98
+
99
+ text-align: right;
100
+ }
101
+
102
+ #sidebar h2 {
103
+ text-transform: uppercase;
104
+
105
+ font-size: 13px;
106
+
107
+ color: #333;
108
+
109
+ letter-spacing: 1px;
110
+
111
+ line-height: 20px;
112
+ }
113
+
114
+ #sidebar ul {
115
+ list-style-type: none;
116
+
117
+ margin: 20px 0;
118
+ }
119
+
120
+ #sidebar li {
121
+ font-size: 14px;
122
+
123
+ line-height: 20px;
124
+ }
125
+ </style>
126
+ </head>
127
+ <body>
128
+ <div id="main">
129
+ <%= @page_rep.content %>
130
+ </div>
131
+ <div id="sidebar">
132
+ <h2>Documentation</h2>
133
+ <ul>
134
+ <li><a href="http://nanoc.stoneship.org/help/tutorial/">Tutorial</a></li>
135
+ <li><a href="http://nanoc.stoneship.org/help/manual/">Manual</a></li>
136
+ </ul>
137
+ <h2>Community</h2>
138
+ <ul>
139
+ <li><a href="http://groups.google.com/group/nanoc/">Discussion Group</a></li>
140
+ <li><a href="http://groups.google.com/group/nanoc-es/">Spanish Discussion Group</a></li>
141
+ <li><a href="http://nanoc.stoneship.org/trac/">Wiki</a></li>
142
+ </ul>
143
+ </div>
144
+ </body>
145
+ </html>
146
+ EOS
147
+
148
+ def name
149
+ 'create_site'
150
+ end
151
+
152
+ def aliases
153
+ [ 'cs' ]
154
+ end
155
+
156
+ def short_desc
157
+ 'create a site'
158
+ end
159
+
160
+ def long_desc
161
+ 'Create a new site at the given path. The site will use the ' +
162
+ 'filesystem data source (but this can be changed later on). It will ' +
163
+ 'also include a few stub rakefiles to make adding new tasks easier.'
164
+ end
165
+
166
+ def usage
167
+ "nanoc2 create_site [path]"
168
+ end
169
+
170
+ def option_definitions
171
+ [
172
+ # --datasource
173
+ {
174
+ :long => 'datasource', :short => 'd', :argument => :required,
175
+ :desc => 'specify the data source for the new site'
176
+ }
177
+ ]
178
+ end
179
+
180
+ def run(options, arguments)
181
+ # Check arguments
182
+ if arguments.length != 1
183
+ $stderr.puts "usage: #{usage}"
184
+ exit 1
185
+ end
186
+
187
+ # Extract arguments and options
188
+ path = arguments[0]
189
+ data_source = options[:datasource] || 'filesystem'
190
+
191
+ # Check whether site exists
192
+ if File.exist?(path)
193
+ $stderr.puts "A site at '#{path}' already exists."
194
+ exit 1
195
+ end
196
+
197
+ # Check whether data source exists
198
+ if Nanoc2::DataSource.named(data_source).nil?
199
+ $stderr.puts "Unrecognised data source: #{data_source}"
200
+ exit 1
201
+ end
202
+
203
+ # Setup notifications
204
+ Nanoc2::NotificationCenter.on(:file_created) do |file_path|
205
+ Nanoc2::CLI::Logger.instance.file(:high, :create, file_path)
206
+ end
207
+
208
+ # Build entire site
209
+ FileUtils.mkdir_p(path)
210
+ FileUtils.cd(File.join(path)) do
211
+ site_create_minimal(data_source)
212
+ site_setup
213
+ site_populate
214
+ end
215
+
216
+ puts "Created a blank nanoc site at '#{path}'. Enjoy!"
217
+ end
218
+
219
+ protected
220
+
221
+ # Creates a configuration file and a output directory for this site, as
222
+ # well as a rakefile and a 'tasks' directory because raking is fun.
223
+ def site_create_minimal(data_source)
224
+ # Create output
225
+ FileUtils.mkdir_p('output')
226
+
227
+ # Create config
228
+ File.open('config.yaml', 'w') do |io|
229
+ io.write "output_dir: \"output\"\n"
230
+ io.write "data_source: \"#{data_source}\"\n"
231
+ io.write "router: \"default\"\n"
232
+ end
233
+ Nanoc2::NotificationCenter.post(:file_created, 'config.yaml')
234
+
235
+ # Create rakefile
236
+ File.open('Rakefile', 'w') do |io|
237
+ io.write "Dir['tasks/**/*.rake'].sort.each { |rakefile| load rakefile }\n"
238
+ io.write "\n"
239
+ io.write "task :default do\n"
240
+ io.write " puts 'This is an example rake task.'\n"
241
+ io.write "end\n"
242
+ end
243
+ Nanoc2::NotificationCenter.post(:file_created, 'Rakefile')
244
+
245
+ # Create tasks
246
+ FileUtils.mkdir_p('tasks')
247
+ File.open('tasks/default.rake', 'w') do |io|
248
+ io.write "task :example do\n"
249
+ io.write " puts 'This is an example rake task in tasks/default.rake.'\n"
250
+ io.write "end\n"
251
+ end
252
+ Nanoc2::NotificationCenter.post(:file_created, 'tasks/default.rake')
253
+ end
254
+
255
+ # Sets up the site's data source, i.e. creates the bare essentials for
256
+ # this data source to work.
257
+ def site_setup
258
+ # Get site
259
+ site = Nanoc2::Site.new(YAML.load_file('config.yaml'))
260
+
261
+ # Set up data source
262
+ site.data_source.loading do
263
+ site.data_source.setup
264
+ end
265
+ end
266
+
267
+ # Populates the site with some initial data, such as a root page, a
268
+ # default layout, a default template, and so on.
269
+ def site_populate
270
+ # Get site
271
+ site = Nanoc2::Site.new(YAML.load_file('config.yaml'))
272
+
273
+ # Create page
274
+ page = Nanoc2::Page.new(
275
+ DEFAULT_PAGE,
276
+ { :title => 'Home' },
277
+ '/'
278
+ )
279
+ page.site = site
280
+ page.save
281
+
282
+ # Fill asset defaults
283
+ Nanoc2::Asset::DEFAULTS.each_pair do |key, value|
284
+ site.asset_defaults.attributes[key] = value
285
+ end
286
+ site.asset_defaults.save
287
+
288
+ # Fill page defaults
289
+ Nanoc2::Page::DEFAULTS.each_pair do |key, value|
290
+ site.page_defaults.attributes[key] = value
291
+ end
292
+ site.page_defaults.save
293
+
294
+ # Create layout
295
+ layout = Nanoc2::Layout.new(
296
+ DEFAULT_LAYOUT,
297
+ { :filter => 'erb' },
298
+ '/default/'
299
+ )
300
+ layout.site = site
301
+ layout.save
302
+
303
+ # Create template
304
+ template = Nanoc2::Template.new(
305
+ "Hi, I'm a new page!\n",
306
+ { :title => "A New Page" },
307
+ 'default'
308
+ )
309
+ template.site = site
310
+ template.save
311
+
312
+ # Fill code
313
+ code = Nanoc2::Code.new(
314
+ "\# All files in the 'lib' directory will be loaded\n" +
315
+ "\# before nanoc starts compiling.\n"
316
+ )
317
+ code.site = site
318
+ code.save
319
+ end
320
+
321
+ end
322
+
323
+ end