nanoc3 3.0.9 → 3.1.0a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/LICENSE +1 -1
  2. data/NEWS.md +360 -0
  3. data/README.md +85 -0
  4. data/Rakefile +2 -2
  5. data/bin/nanoc3 +0 -4
  6. data/lib/nanoc3/base/code_snippet.rb +14 -6
  7. data/lib/nanoc3/base/compiler.rb +68 -49
  8. data/lib/nanoc3/base/compiler_dsl.rb +70 -29
  9. data/lib/nanoc3/base/context.rb +47 -0
  10. data/lib/nanoc3/base/core_ext/array.rb +4 -0
  11. data/lib/nanoc3/base/core_ext/hash.rb +5 -1
  12. data/lib/nanoc3/base/core_ext/string.rb +2 -0
  13. data/lib/nanoc3/base/data_source.rb +132 -96
  14. data/lib/nanoc3/base/dependency_tracker.rb +160 -185
  15. data/lib/nanoc3/base/directed_graph.rb +252 -0
  16. data/lib/nanoc3/base/errors.rb +52 -4
  17. data/lib/nanoc3/base/filter.rb +43 -28
  18. data/lib/nanoc3/base/item.rb +93 -25
  19. data/lib/nanoc3/base/item_rep.rb +166 -55
  20. data/lib/nanoc3/base/layout.rb +16 -13
  21. data/lib/nanoc3/base/notification_center.rb +28 -12
  22. data/lib/nanoc3/base/plugin_registry.rb +158 -0
  23. data/lib/nanoc3/base/rule.rb +27 -8
  24. data/lib/nanoc3/base/rule_context.rb +59 -46
  25. data/lib/nanoc3/base/site.rb +124 -77
  26. data/lib/nanoc3/base.rb +7 -2
  27. data/lib/nanoc3/cli/base.rb +4 -1
  28. data/lib/nanoc3/cli/commands/autocompile.rb +5 -4
  29. data/lib/nanoc3/cli/commands/compile.rb +28 -7
  30. data/lib/nanoc3/cli/commands/create_item.rb +1 -1
  31. data/lib/nanoc3/cli/commands/create_layout.rb +1 -1
  32. data/lib/nanoc3/cli/commands/create_site.rb +46 -22
  33. data/lib/nanoc3/cli/commands/debug.rb +100 -0
  34. data/lib/nanoc3/cli/commands/help.rb +1 -1
  35. data/lib/nanoc3/cli/commands/info.rb +1 -1
  36. data/lib/nanoc3/cli/commands/view.rb +85 -0
  37. data/lib/nanoc3/cli/commands.rb +2 -0
  38. data/lib/nanoc3/cli/logger.rb +7 -0
  39. data/lib/nanoc3/cli.rb +0 -3
  40. data/lib/nanoc3/data_sources/{delicious.rb → deprecated/delicious.rb} +1 -24
  41. data/lib/nanoc3/data_sources/{last_fm.rb → deprecated/last_fm.rb} +1 -27
  42. data/lib/nanoc3/data_sources/{twitter.rb → deprecated/twitter.rb} +1 -14
  43. data/lib/nanoc3/data_sources/filesystem.rb +188 -176
  44. data/lib/nanoc3/data_sources/filesystem_unified.rb +107 -0
  45. data/lib/nanoc3/data_sources/filesystem_verbose.rb +80 -0
  46. data/lib/nanoc3/data_sources.rb +18 -9
  47. data/lib/nanoc3/extra/core_ext/enumerable.rb +39 -0
  48. data/lib/nanoc3/extra/core_ext/time.rb +2 -2
  49. data/lib/nanoc3/extra/core_ext.rb +1 -0
  50. data/lib/nanoc3/extra/deployers/rsync.rb +49 -3
  51. data/lib/nanoc3/extra/file_proxy.rb +7 -0
  52. data/lib/nanoc3/extra/vcs.rb +25 -24
  53. data/lib/nanoc3/extra/vcses/bazaar.rb +4 -0
  54. data/lib/nanoc3/extra/vcses/dummy.rb +4 -0
  55. data/lib/nanoc3/extra/vcses/git.rb +4 -0
  56. data/lib/nanoc3/extra/vcses/mercurial.rb +4 -0
  57. data/lib/nanoc3/extra/vcses/subversion.rb +4 -0
  58. data/lib/nanoc3/extra.rb +4 -1
  59. data/lib/nanoc3/filters/erb.rb +1 -1
  60. data/lib/nanoc3/filters/erubis.rb +1 -1
  61. data/lib/nanoc3/filters/haml.rb +1 -1
  62. data/lib/nanoc3/filters/kramdown.rb +14 -0
  63. data/lib/nanoc3/filters/maruku.rb +1 -1
  64. data/lib/nanoc3/filters/rainpress.rb +1 -1
  65. data/lib/nanoc3/filters/rdiscount.rb +3 -1
  66. data/lib/nanoc3/filters.rb +2 -0
  67. data/lib/nanoc3/helpers/blogging.rb +91 -75
  68. data/lib/nanoc3/helpers/breadcrumbs.rb +18 -10
  69. data/lib/nanoc3/helpers/capturing.rb +24 -29
  70. data/lib/nanoc3/helpers/filtering.rb +20 -17
  71. data/lib/nanoc3/helpers/html_escape.rb +7 -4
  72. data/lib/nanoc3/helpers/link_to.rb +51 -41
  73. data/lib/nanoc3/helpers/rendering.rb +15 -8
  74. data/lib/nanoc3/helpers/tagging.rb +27 -21
  75. data/lib/nanoc3/helpers/text.rb +12 -8
  76. data/lib/nanoc3/helpers/xml_sitemap.rb +13 -15
  77. data/lib/nanoc3/tasks/deploy/rsync.rake +4 -1
  78. data/lib/nanoc3/tasks.rb +2 -1
  79. data/lib/nanoc3.rb +24 -1
  80. metadata +43 -87
  81. data/NEWS.rdoc +0 -328
  82. data/README.rdoc +0 -83
  83. data/lib/nanoc3/base/plugin.rb +0 -88
  84. data/lib/nanoc3/base/preprocessor_context.rb +0 -37
  85. data/lib/nanoc3/data_sources/filesystem_combined.rb +0 -214
  86. data/lib/nanoc3/data_sources/filesystem_common.rb +0 -22
  87. data/lib/nanoc3/data_sources/filesystem_compact.rb +0 -256
  88. data/lib/nanoc3/extra/context.rb +0 -24
  89. data/lib/nanoc3/package.rb +0 -107
  90. data/vendor/cri/ChangeLog +0 -0
  91. data/vendor/cri/LICENSE +0 -19
  92. data/vendor/cri/NEWS +0 -0
  93. data/vendor/cri/README +0 -4
  94. data/vendor/cri/Rakefile +0 -25
  95. data/vendor/cri/lib/cri/base.rb +0 -153
  96. data/vendor/cri/lib/cri/command.rb +0 -105
  97. data/vendor/cri/lib/cri/core_ext/string.rb +0 -41
  98. data/vendor/cri/lib/cri/core_ext.rb +0 -8
  99. data/vendor/cri/lib/cri/option_parser.rb +0 -186
  100. data/vendor/cri/lib/cri.rb +0 -12
  101. data/vendor/cri/test/test_base.rb +0 -6
  102. data/vendor/cri/test/test_command.rb +0 -6
  103. data/vendor/cri/test/test_core_ext.rb +0 -21
  104. data/vendor/cri/test/test_option_parser.rb +0 -279
@@ -4,6 +4,39 @@ module Nanoc3::CLI::Commands
4
4
 
5
5
  class CreateSite < Cri::Command
6
6
 
7
+ DEFAULT_RULES = <<EOS
8
+ #!/usr/bin/env ruby
9
+
10
+ # A few helpful tips about the Rules file:
11
+ #
12
+ # * The order of rules is important: for each item, only the first matching
13
+ # rule is applied.
14
+ #
15
+ # * Item identifiers start and end with a slash (e.g. “/about/” for the file
16
+ # “content/about.html”). To select all children, grandchildren, … of an
17
+ # item, use the pattern “/about/*/”; “/about/*” will also select the parent,
18
+ # because “*” matches zero or more characters.
19
+
20
+ compile '/stylesheet/' do
21
+ # don’t filter or layout
22
+ end
23
+
24
+ compile '*' do
25
+ filter :erb
26
+ layout 'default'
27
+ end
28
+
29
+ route '/stylesheet/' do
30
+ '/style.css'
31
+ end
32
+
33
+ route '*' do
34
+ item.identifier + 'index.html'
35
+ end
36
+
37
+ layout '*', :erb
38
+ EOS
39
+
7
40
  DEFAULT_ITEM = <<EOS
8
41
  <h1>A Brand New nanoc Site</h1>
9
42
 
@@ -128,6 +161,7 @@ EOS
128
161
  <title>A Brand New nanoc Site - <%= @item[:title] %></title>
129
162
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
130
163
  <link rel="stylesheet" type="text/css" href="/style.css" media="screen">
164
+ <meta name="generator" content="nanoc #{Nanoc3::VERSION}">
131
165
  </head>
132
166
  <body>
133
167
  <div id="main">
@@ -169,7 +203,7 @@ EOS
169
203
  end
170
204
 
171
205
  def usage
172
- "nanoc3 create_site [path]"
206
+ "nanoc3 create_site [options] path"
173
207
  end
174
208
 
175
209
  def option_definitions
@@ -252,18 +286,7 @@ EOS
252
286
 
253
287
  # Create rules
254
288
  File.open('Rules', 'w') do |io|
255
- io.write "#!/usr/bin/env ruby\n"
256
- io.write "\n"
257
- io.write "compile '*' do\n"
258
- io.write " filter :erb\n"
259
- io.write " layout 'default'\n"
260
- io.write "end\n"
261
- io.write "\n"
262
- io.write "route '*' do\n"
263
- io.write " item.identifier + 'index.html'\n"
264
- io.write "end\n"
265
- io.write "\n"
266
- io.write "layout '*', :erb\n"
289
+ io.write DEFAULT_RULES
267
290
  end
268
291
  Nanoc3::NotificationCenter.post(:file_created, 'Rules')
269
292
  end
@@ -285,29 +308,30 @@ EOS
285
308
  def site_populate
286
309
  # Get site
287
310
  site = Nanoc3::Site.new('.')
288
-
289
- # Create item
290
311
  data_source = site.data_sources[0]
312
+
313
+ # Create home page
291
314
  data_source.create_item(
292
315
  DEFAULT_ITEM,
293
316
  { :title => "Home" },
294
317
  '/'
295
318
  )
296
319
 
320
+ # Create stylesheet
321
+ data_source.create_item(
322
+ DEFAULT_STYLESHEET,
323
+ {},
324
+ '/stylesheet/',
325
+ :extension => '.css'
326
+ )
327
+
297
328
  # Create layout
298
- data_source = site.data_sources[0]
299
329
  data_source.create_layout(
300
330
  DEFAULT_LAYOUT,
301
331
  {},
302
332
  '/default/'
303
333
  )
304
334
 
305
- # Create stylesheet
306
- FileUtils.mkdir_p('output')
307
- File.open('output/style.css', 'w') do |io|
308
- io.write DEFAULT_STYLESHEET
309
- end
310
-
311
335
  # Create code
312
336
  FileUtils.mkdir_p('lib')
313
337
  File.open('lib/default.rb', 'w') do |io|
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::CLI::Commands
4
+
5
+ class Debug < Cri::Command
6
+
7
+ def name
8
+ 'debug'
9
+ end
10
+
11
+ def aliases
12
+ []
13
+ end
14
+
15
+ def short_desc
16
+ 'show debug information for this site'
17
+ end
18
+
19
+ def long_desc
20
+ 'Show information about all items, item representations and layouts ' \
21
+ 'in the current site.'
22
+ end
23
+
24
+ def usage
25
+ "nanoc3 debug"
26
+ end
27
+
28
+ def option_definitions
29
+ []
30
+ end
31
+
32
+ def run(options, arguments)
33
+ # Make sure we are in a nanoc site directory
34
+ print "Loading site data... "
35
+ @base.require_site
36
+ @base.site.load_data
37
+ puts "done"
38
+ puts
39
+
40
+ # Get data
41
+ items = @base.site.items
42
+ reps = items.map { |i| i.reps }.flatten
43
+ layouts = @base.site.layouts
44
+
45
+ # Calculate prettification data
46
+ identifier_length = items.map { |i| i.identifier.size }.max
47
+ rep_name_length = reps.map { |r| r.name.size }.max
48
+
49
+ # Print items
50
+ puts '=== Items'
51
+ puts
52
+ row = 0
53
+ items.sort_by { |i| i.identifier }.each do |item|
54
+ item.reps.sort_by { |r| r.name.to_s }.each do |rep|
55
+ # Determine filler
56
+ filler = (row % 3 == 0 ? '· ' : ' ')
57
+ row += 1
58
+
59
+ # Print rep
60
+ puts "* %s %s -> %s" % [
61
+ fill(item.identifier, identifier_length, filler),
62
+ fill(rep.name.to_s, rep_name_length, ' '),
63
+ rep.raw_path || '-'
64
+ ]
65
+ end
66
+ end
67
+ puts
68
+
69
+ # Print layouts
70
+ puts '=== Layouts'
71
+ puts
72
+ layouts.each do |layout|
73
+ puts "* #{layout.identifier}"
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ # Returns a string that is exactly `length` long, starting with `text` and
80
+ # filling up any unused space by repeating the string `filler`.
81
+ def fill(text, length, filler)
82
+ res = text.dup
83
+
84
+ filler_length = (length - 1 - text.length)
85
+ if filler_length >= 0
86
+ # Append spacer to ensure alignment
87
+ spacer_length = text.size % filler.length
88
+ filler_length -= spacer_length
89
+ res << ' ' * (spacer_length + 1)
90
+
91
+ # Append leader
92
+ res << filler*(filler_length/filler.length)
93
+ end
94
+
95
+ res
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -25,7 +25,7 @@ module Nanoc3::CLI::Commands
25
25
  end
26
26
 
27
27
  def usage
28
- "nanoc3 help [command]"
28
+ "nanoc3 help [options] [command]"
29
29
  end
30
30
 
31
31
  def run(options, arguments)
@@ -23,7 +23,7 @@ module Nanoc3::CLI::Commands
23
23
  end
24
24
 
25
25
  def usage
26
- "nanoc3 info"
26
+ "nanoc3 info [options]"
27
27
  end
28
28
 
29
29
  def option_definitions
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::CLI::Commands
4
+
5
+ class View < Cri::Command
6
+
7
+ def name
8
+ 'view'
9
+ end
10
+
11
+ def aliases
12
+ []
13
+ end
14
+
15
+ def short_desc
16
+ 'start the web server that serves static files'
17
+ end
18
+
19
+ def long_desc
20
+ 'Start the static web server. Unless specified, the web server will run on port 3000 and listen on all IP addresses. Running the autocompiler requires \'adsf\' and \'rack\'.'
21
+ end
22
+
23
+ def usage
24
+ "nanoc3 view [options]"
25
+ end
26
+
27
+ def option_definitions
28
+ [
29
+ # --handler
30
+ {
31
+ :long => 'handler', :short => 'H', :argument => :required,
32
+ :desc => 'specify the handler to use (webrick/mongrel/...)'
33
+ },
34
+ # --host
35
+ {
36
+ :long => 'host', :short => 'o', :argument => :required,
37
+ :desc => 'specify the host to listen on (default: 0.0.0.0)'
38
+ },
39
+ # --port
40
+ {
41
+ :long => 'port', :short => 'p', :argument => :required,
42
+ :desc => 'specify the port to listen on (default: 3000)'
43
+ }
44
+ ]
45
+ end
46
+
47
+ def run(options, arguments)
48
+ require 'rack'
49
+ require 'adsf'
50
+
51
+ # Make sure we are in a nanoc site directory
52
+ @base.require_site
53
+
54
+ # Set options
55
+ options_for_rack = {
56
+ :Port => (options[:port] || 3000).to_i,
57
+ :Host => (options[:host] || '0.0.0.0')
58
+ }
59
+
60
+ # Guess which handler we should use
61
+ unless handler = Rack::Handler.get(options[:handler])
62
+ begin
63
+ handler = Rack::Handler::Mongrel
64
+ rescue LoadError => e
65
+ handler = Rack::Handler::WEBrick
66
+ end
67
+ end
68
+
69
+ # Build app
70
+ site = @base.site
71
+ app = Rack::Builder.new do
72
+ use Rack::CommonLogger
73
+ use Rack::ShowExceptions
74
+ use Rack::Lint
75
+ use Adsf::Rack::IndexFileFinder, :root => site.config[:output_dir]
76
+ run Rack::File.new(site.config[:output_dir])
77
+ end.to_app
78
+
79
+ # Run autocompiler
80
+ handler.run(app, options_for_rack)
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -8,6 +8,8 @@ require 'nanoc3/cli/commands/compile'
8
8
  require 'nanoc3/cli/commands/create_layout'
9
9
  require 'nanoc3/cli/commands/create_item'
10
10
  require 'nanoc3/cli/commands/create_site'
11
+ require 'nanoc3/cli/commands/debug'
11
12
  require 'nanoc3/cli/commands/help'
12
13
  require 'nanoc3/cli/commands/info'
13
14
  require 'nanoc3/cli/commands/update'
15
+ require 'nanoc3/cli/commands/view'
@@ -29,6 +29,13 @@ module Nanoc3::CLI
29
29
  def initialize
30
30
  @level = :high
31
31
  @color = true
32
+
33
+ # Try enabling color support on Windows
34
+ begin
35
+ require 'Win32/Console/ANSI' if RUBY_PLATFORM =~/mswin|mingw/
36
+ rescue LoadError
37
+ warn 'The win32console gem is not available. Install it to enable color support on Windows.'
38
+ end
32
39
  end
33
40
 
34
41
  # Logs a file-related action.
data/lib/nanoc3/cli.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- # Add Cri to load path
4
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../../vendor/cri/lib'))
5
-
6
3
  # Load Cri
7
4
  require 'cri'
8
5
 
@@ -2,30 +2,7 @@
2
2
 
3
3
  module Nanoc3::DataSources
4
4
 
5
- # Nanoc3::DataSources::Delicious provides for a delicious.com bookmarks from
6
- # a single user as items (Nanoc3::Item instances).
7
- #
8
- # The configuration must have a "username" attribute containing the username
9
- # of the account from which to fetch the bookmarks.
10
- #
11
- # The items returned by this data source will be mounted at {root}/{id},
12
- # where +id+ is a sequence number that is not necessarily unique for this
13
- # bookmark (because delicious.com unfortunately does not provide unique IDs
14
- # for each bookmark).
15
- #
16
- # The items returned by this data source will have the following attributes:
17
- #
18
- # +:url+:: The URL the bookmark leads to.
19
- #
20
- # +:description+:: The description (title, usually) of the bookmark.
21
- #
22
- # +:tags+:: An array of tags (strings) for this bookmark.
23
- #
24
- # +:date+:: The timestamp when this bookmark was created (a Time object).
25
- #
26
- # +:note+:: The personal note for this bookmark (can be nil).
27
- #
28
- # +:author+:: The username of the person storing the bookmark.
5
+ # @deprecated Fetch data from online data sources manually instead
29
6
  class Delicious < Nanoc3::DataSource
30
7
 
31
8
  def items
@@ -2,33 +2,7 @@
2
2
 
3
3
  module Nanoc3::DataSources
4
4
 
5
- # Nanoc3::DataSources::LastFM provides data about recently played tracks
6
- # from from a single Last.fm user as items (Nanoc3::Item instances).
7
- #
8
- # The configuration must have a "username" attribute containing the username
9
- # of the account from which to fetch the data, and an "api_key" attribute
10
- # containing the API key (which can be obtained from the Last.fm site).
11
- #
12
- # The items returned by this data source will be mounted at {root}/{id},
13
- # where +id+ is a sequence number that is not necessarily unique for this
14
- # bookmark (because delicious.com unfortunately does not provide unique IDs
15
- # for each track).
16
- #
17
- # The items returned by this data source will have the following attributes:
18
- #
19
- # +:name+:: The name of the track.
20
- #
21
- # +played_at+:: The timestamp when the track was played (a Time instance).
22
- #
23
- # +url+:: The Last.fm URL corresponding to the track (a String instance).
24
- #
25
- # +artist+:: A hash containing information about the track's artist.
26
- #
27
- # The +artist+ hash consists of the following keys:
28
- #
29
- # +name+:: The name of the artist.
30
- #
31
- # +url+:: The Last.fm URL corresponding to the artist (a String instance).
5
+ # @deprecated Fetch data from online data sources manually instead
32
6
  class LastFM < Nanoc3::DataSource
33
7
 
34
8
  def items
@@ -2,20 +2,7 @@
2
2
 
3
3
  module Nanoc3::DataSources
4
4
 
5
- # Nanoc3::DataSources::Twitter provides tweets from a single user as items
6
- # (Nanoc3::Item instances).
7
- #
8
- # The configuration must have a "username" attribute containing the username
9
- # of the account from which to fetch the tweets.
10
- #
11
- # The items returned by this data source will be mounted at {root}/{id},
12
- # where +id+ is the unique identifier of the tweet.
13
- #
14
- # The items returned by this data source will have the following attributes:
15
- #
16
- # +:created_at+:: The timestamp when this tweet was posted (a string).
17
- #
18
- # +source+:: The client used to tweet this message (HTML-encoded).
5
+ # @deprecated Fetch data from online data sources manually instead
19
6
  class Twitter < Nanoc3::DataSource
20
7
 
21
8
  def items