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
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::Extra::EnumerableExtensions
4
+
5
+ module GroupBy
6
+
7
+ # Returns a hash, which keys are evaluated result from the block, and
8
+ # values are arrays of elements in enum corresponding to the key. This
9
+ # method is provided for backward compatibility with Ruby 1.8.6 and lower,
10
+ # since {#group_by} is only available in 1.8.7 and higher.
11
+ #
12
+ # @yieldparam [Object] obj The object to classify
13
+ #
14
+ # @return [Hash]
15
+ #
16
+ # @example Grouping integers by rest by division through 3
17
+ #
18
+ # (1..6).group_by { |i| i % 3 }
19
+ # # => { 0 => [3, 6], 1 => [1, 4], 2 => [2, 5] }
20
+ def group_by
21
+ groups = {}
22
+ each do |item|
23
+ key = yield(item)
24
+
25
+ groups[key] ||= []
26
+ groups[key] << item
27
+ end
28
+ groups
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
35
+ module Enumerable
36
+ if !Enumerable.instance_methods.include?('group_by')
37
+ include Nanoc3::Extra::EnumerableExtensions::GroupBy
38
+ end
39
+ end
@@ -2,12 +2,12 @@
2
2
 
3
3
  module Nanoc3::Extra::TimeExtensions
4
4
 
5
- # Returns a string with the time in an ISO-8601 date format.
5
+ # @return [String] The time in an ISO-8601 date format.
6
6
  def to_iso8601_date
7
7
  self.strftime("%Y-%m-%d")
8
8
  end
9
9
 
10
- # Returns a string with the time in an ISO-8601 time format.
10
+ # @return [String] The time in an ISO-8601 time format.
11
11
  def to_iso8601_time
12
12
  self.gmtime.strftime("%Y-%m-%dT%H:%M:%SZ")
13
13
  end
@@ -1,3 +1,4 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'nanoc3/extra/core_ext/enumerable'
3
4
  require 'nanoc3/extra/core_ext/time'
@@ -5,8 +5,54 @@ module Nanoc3::Extra::Deployers
5
5
  # Nanoc3::Extra::Deployers::Rsync is a deployer that deploys a site using rsync.
6
6
  class Rsync
7
7
 
8
- # Creates a new deployment task that uses rsync. The deployment
9
- # configuration will be taken from the site's configuration file.
8
+ DEFAULT_OPTIONS = [
9
+ '-glpPrtvz',
10
+ '--exclude=".hg"',
11
+ '--exclude=".svn"',
12
+ '--exclude=".git"'
13
+ ]
14
+
15
+ # Creates a new deployer that uses rsync. The deployment configurations
16
+ # will be read from the configuration file of the site (which is assumed
17
+ # to be the current working directory).
18
+ #
19
+ # The deployment configurations are stored like this in the site's
20
+ # configuration file:
21
+ #
22
+ # deploy:
23
+ # NAME:
24
+ # options: [ OPTIONS ]
25
+ # dst: "DST"
26
+ #
27
+ # +NAME+ is a unique name for the deployment configuration. By default,
28
+ # the deployer will use the deployment configuration named "default".
29
+ #
30
+ # +OPTIONS+ is an array containing options to pass to the rsync
31
+ # executable. This is not required; by default, +-glpPrtvz+ and
32
+ # +--exclude+s for +.svn+, +.hg+ and +.git+ are used.
33
+ #
34
+ # +DST+ is a string containing the destination to where rsync should
35
+ # upload its data. It will likely be in +host:path+ format. For example,
36
+ # "example.com:/var/www/sites/mysite/html". It should not end with a
37
+ # trailing slash.
38
+ #
39
+ # Example: This deployment configuration defines a "default" and a
40
+ # "staging" deployment configuration. The default options are used.
41
+ #
42
+ # deploy:
43
+ # default:
44
+ # dst: "ectype:sites/stoneship/public"
45
+ # staging:
46
+ # dst: "ectype:sites/stoneship-staging/public"
47
+ # options: [ "-glpPrtvz" ]
48
+ #
49
+ # When running the deployer with the "default" resp. "staging"
50
+ # configurations, the following rsync commands will be executed:
51
+ #
52
+ # rsync -glpPrtvz --exclude=".hg" --exclude=".svn"
53
+ # --exclude=".git" output ectype:sites/stoneship/public
54
+ #
55
+ # rsync -glpPrtvz output ectype:sites/stoneship-staging/public
10
56
  def initialize
11
57
  # Get site
12
58
  error 'No site configuration found' unless File.file?('config.yaml')
@@ -32,7 +78,7 @@ module Nanoc3::Extra::Deployers
32
78
  # Set arguments
33
79
  src = File.expand_path(@site.config[:output_dir]) + '/'
34
80
  dst = @site.config[:deploy][config_name][:dst]
35
- options = @site.config[:deploy][config_name][:options] || []
81
+ options = @site.config[:deploy][config_name][:options] || DEFAULT_OPTIONS
36
82
 
37
83
  # Validate arguments
38
84
  error 'No dst found in deployment configuration' if dst.nil?
@@ -12,6 +12,8 @@ module Nanoc3::Extra
12
12
 
13
13
  instance_methods.each { |m| undef_method m unless m =~ /^__/ || m.to_s == 'object_id' }
14
14
 
15
+ @@deprecation_warning_shown = false
16
+
15
17
  # Creates a new file proxy for the given path. This is similar to
16
18
  # creating a File object with the same path, except that the File object
17
19
  # will not be created until it is accessed.
@@ -29,6 +31,11 @@ module Nanoc3::Extra
29
31
  # be created right before the method call takes place and destroyed
30
32
  # right after.
31
33
  def method_missing(sym, *args, &block)
34
+ if !@@deprecation_warning_shown
35
+ $stderr.puts 'WARNING: The :file attribute is deprecated and will be removed in a future version of nanoc. Instead of using this :file attribute, consider manually creating a File object when it’s needed, using the :content_filename or :meta_filename attributes (for filesystem_verbose and filesystem_compact) or :filename (for filesystem_combined).'
36
+ @@deprecation_warning_shown = true
37
+ end
38
+
32
39
  File.open(@path, 'r') { |io| io.__send__(sym, *args, &block) }
33
40
  end
34
41
 
@@ -2,33 +2,24 @@
2
2
 
3
3
  module Nanoc3::Extra
4
4
 
5
- # Nanoc3::Extra::VCS is a very simple representation of a version control
6
- # system that abstracts the add, remove and move operations. It does not
7
- # commit. This class is primarily used by data sources that store data as
8
- # flat files on the disk.
5
+ # A very simple representation of a version control system (VCS) that
6
+ # abstracts the add, remove and move operations. It does not commit. This
7
+ # class is primarily used by data sources that store data as flat files on
8
+ # the disk.
9
9
  #
10
- # This is the abstract superclass for all VCSes. Subclasses should implement
11
- # the indicated methods.
12
- class VCS < Nanoc3::Plugin
10
+ # @abstract Subclass and override {#add}, {#remove} and {#move} to implement
11
+ # a custom VCS.
12
+ class VCS
13
13
 
14
- # Sets the identifiers for this VCS.
15
- def self.identifiers(*identifiers)
16
- Nanoc3::Extra::VCS.register(self, *identifiers)
17
- end
18
-
19
- # Sets the identifier for this VCS.
20
- def self.identifier(identifier)
21
- Nanoc3::Extra::VCS.register(self, identifier)
22
- end
23
-
24
- # Registers the given class as a VCS with the given identifier.
25
- def self.register(class_or_name, *identifiers)
26
- Nanoc3::Plugin.register(Nanoc3::Extra::VCS, class_or_name, *identifiers)
27
- end
14
+ extend Nanoc3::PluginRegistry::PluginMethods
28
15
 
29
16
  # Adds the file with the given filename to the working copy.
30
17
  #
31
- # Subclasses must implement this method.
18
+ # @param [String] filename The name of the file to add
19
+ #
20
+ # @return [void]
21
+ #
22
+ # @abstract
32
23
  def add(filename)
33
24
  not_implemented('add')
34
25
  end
@@ -37,7 +28,11 @@ module Nanoc3::Extra
37
28
  # this method is executed, the file should no longer be present on the
38
29
  # disk.
39
30
  #
40
- # Subclasses must implement this method.
31
+ # @param [String] filename The name of the file to remove
32
+ #
33
+ # @return [void]
34
+ #
35
+ # @abstract
41
36
  def remove(filename)
42
37
  not_implemented('remove')
43
38
  end
@@ -46,7 +41,13 @@ module Nanoc3::Extra
46
41
  # method is executed, the original file should no longer be present on the
47
42
  # disk.
48
43
  #
49
- # Subclasses must implement this method.
44
+ # @param [String] src The old filename
45
+ #
46
+ # @param [String] dst The new filename
47
+ #
48
+ # @return [void]
49
+ #
50
+ # @abstract
50
51
  def move(src, dst)
51
52
  not_implemented('move')
52
53
  end
@@ -2,16 +2,20 @@
2
2
 
3
3
  module Nanoc3::Extra::VCSes
4
4
 
5
+ # @see Nanoc3::Extra::VCS
5
6
  class Bazaar < Nanoc3::Extra::VCS
6
7
 
8
+ # @see Nanoc3::Extra::VCS#add
7
9
  def add(filename)
8
10
  system('bzr', 'add', filename)
9
11
  end
10
12
 
13
+ # @see Nanoc3::Extra::VCS#remove
11
14
  def remove(filename)
12
15
  system('bzr', 'rm', filename)
13
16
  end
14
17
 
18
+ # @see Nanoc3::Extra::VCS#move
15
19
  def move(src, dst)
16
20
  system('bzr', 'mv', src, dst)
17
21
  end
@@ -2,15 +2,19 @@
2
2
 
3
3
  module Nanoc3::Extra::VCSes
4
4
 
5
+ # @see Nanoc3::Extra::VCS
5
6
  class Dummy < Nanoc3::Extra::VCS
6
7
 
8
+ # @see Nanoc3::Extra::VCS#add
7
9
  def add(filename)
8
10
  end
9
11
 
12
+ # @see Nanoc3::Extra::VCS#remove
10
13
  def remove(filename)
11
14
  FileUtils.rm_rf(filename)
12
15
  end
13
16
 
17
+ # @see Nanoc3::Extra::VCS#move
14
18
  def move(src, dst)
15
19
  FileUtils.move(src, dst)
16
20
  end
@@ -2,16 +2,20 @@
2
2
 
3
3
  module Nanoc3::Extra::VCSes
4
4
 
5
+ # @see Nanoc3::Extra::VCS
5
6
  class Git < Nanoc3::Extra::VCS
6
7
 
8
+ # @see Nanoc3::Extra::VCS#add
7
9
  def add(filename)
8
10
  system('git', 'add', filename)
9
11
  end
10
12
 
13
+ # @see Nanoc3::Extra::VCS#remove
11
14
  def remove(filename)
12
15
  system('git', 'rm', filename)
13
16
  end
14
17
 
18
+ # @see Nanoc3::Extra::VCS#move
15
19
  def move(src, dst)
16
20
  system('git', 'mv', src, dst)
17
21
  end
@@ -2,16 +2,20 @@
2
2
 
3
3
  module Nanoc3::Extra::VCSes
4
4
 
5
+ # @see Nanoc3::Extra::VCS
5
6
  class Mercurial < Nanoc3::Extra::VCS
6
7
 
8
+ # @see Nanoc3::Extra::VCS#add
7
9
  def add(filename)
8
10
  system('hg', 'add', filename)
9
11
  end
10
12
 
13
+ # @see Nanoc3::Extra::VCS#remove
11
14
  def remove(filename)
12
15
  system('hg', 'rm', filename)
13
16
  end
14
17
 
18
+ # @see Nanoc3::Extra::VCS#move
15
19
  def move(src, dst)
16
20
  system('hg', 'mv', src, dst)
17
21
  end
@@ -2,16 +2,20 @@
2
2
 
3
3
  module Nanoc3::Extra::VCSes
4
4
 
5
+ # @see Nanoc3::Extra::VCS
5
6
  class Subversion < Nanoc3::Extra::VCS
6
7
 
8
+ # @see Nanoc3::Extra::VCS#add
7
9
  def add(filename)
8
10
  system('svn', 'add', filename)
9
11
  end
10
12
 
13
+ # @see Nanoc3::Extra::VCS#remove
11
14
  def remove(filename)
12
15
  system('svn', 'rm', filename)
13
16
  end
14
17
 
18
+ # @see Nanoc3::Extra::VCS#move
15
19
  def move(src, dst)
16
20
  system('svn', 'mv', src, dst)
17
21
  end
data/lib/nanoc3/extra.rb CHANGED
@@ -4,11 +4,14 @@ module Nanoc3::Extra
4
4
 
5
5
  autoload 'AutoCompiler', 'nanoc3/extra/auto_compiler'
6
6
  autoload 'CHiCk', 'nanoc3/extra/chick'
7
- autoload 'Context', 'nanoc3/extra/context'
8
7
  autoload 'Deployers', 'nanoc3/extra/deployers'
9
8
  autoload 'FileProxy', 'nanoc3/extra/file_proxy'
10
9
  autoload 'Validators', 'nanoc3/extra/validators'
11
10
 
11
+ # Deprecated; use {Nanoc3::Context} instead
12
+ # TODO [in nanoc 4.0] remove me
13
+ Context = ::Nanoc3::Context
14
+
12
15
  end
13
16
 
14
17
  require 'nanoc3/extra/core_ext'
@@ -7,7 +7,7 @@ module Nanoc3::Filters
7
7
  require 'erb'
8
8
 
9
9
  # Create context
10
- context = ::Nanoc3::Extra::Context.new(assigns)
10
+ context = ::Nanoc3::Context.new(assigns)
11
11
 
12
12
  # Get result
13
13
  erb = ::ERB.new(content)
@@ -7,7 +7,7 @@ module Nanoc3::Filters
7
7
  require 'erubis'
8
8
 
9
9
  # Create context
10
- context = ::Nanoc3::Extra::Context.new(assigns)
10
+ context = ::Nanoc3::Context.new(assigns)
11
11
 
12
12
  # Get result
13
13
  ::Erubis::Eruby.new(content, :filename => filename).result(context.get_binding { assigns[:content] })
@@ -10,7 +10,7 @@ module Nanoc3::Filters
10
10
  options = params.merge(:filename => filename)
11
11
 
12
12
  # Create context
13
- context = ::Nanoc3::Extra::Context.new(assigns)
13
+ context = ::Nanoc3::Context.new(assigns)
14
14
 
15
15
  # Get result
16
16
  ::Haml::Engine.new(content, options).render(context, assigns) { assigns[:content] }
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::Filters
4
+ class Kramdown < Nanoc3::Filter
5
+
6
+ def run(content, params={})
7
+ require 'kramdown'
8
+
9
+ # Get result
10
+ ::Kramdown::Document.new(content, params).to_html
11
+ end
12
+
13
+ end
14
+ end
@@ -7,7 +7,7 @@ module Nanoc3::Filters
7
7
  require 'maruku'
8
8
 
9
9
  # Get result
10
- ::Maruku.new(content).to_html
10
+ ::Maruku.new(content, params).to_html
11
11
  end
12
12
 
13
13
  end
@@ -6,7 +6,7 @@ module Nanoc3::Filters
6
6
  def run(content, params={})
7
7
  require 'rainpress'
8
8
 
9
- ::Rainpress.compress(content)
9
+ ::Rainpress.compress(content, params)
10
10
  end
11
11
 
12
12
  end
@@ -6,7 +6,9 @@ module Nanoc3::Filters
6
6
  def run(content, params={})
7
7
  require 'rdiscount'
8
8
 
9
- ::RDiscount.new(content).to_html
9
+ extensions = params[:extensions] || []
10
+
11
+ ::RDiscount.new(content, *extensions).to_html
10
12
  end
11
13
 
12
14
  end
@@ -7,6 +7,7 @@ module Nanoc3::Filters
7
7
  autoload 'ERB', 'nanoc3/filters/erb'
8
8
  autoload 'Erubis', 'nanoc3/filters/erubis'
9
9
  autoload 'Haml', 'nanoc3/filters/haml'
10
+ autoload 'Kramdown', 'nanoc3/filters/kramdown'
10
11
  autoload 'Less', 'nanoc3/filters/less'
11
12
  autoload 'Markaby', 'nanoc3/filters/markaby'
12
13
  autoload 'Maruku', 'nanoc3/filters/maruku'
@@ -23,6 +24,7 @@ module Nanoc3::Filters
23
24
  Nanoc3::Filter.register '::Nanoc3::Filters::ERB', :erb
24
25
  Nanoc3::Filter.register '::Nanoc3::Filters::Erubis', :erubis
25
26
  Nanoc3::Filter.register '::Nanoc3::Filters::Haml', :haml
27
+ Nanoc3::Filter.register '::Nanoc3::Filters::Kramdown', :kramdown
26
28
  Nanoc3::Filter.register '::Nanoc3::Filters::Less', :less
27
29
  Nanoc3::Filter.register '::Nanoc3::Filters::Markaby', :markaby
28
30
  Nanoc3::Filter.register '::Nanoc3::Filters::Maruku', :maruku