nanoc3 3.1.0a1 → 3.1.0a2

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS.md CHANGED
@@ -14,6 +14,7 @@ New:
14
14
  * A plugin-loading system
15
15
  * A diff between the previously compiled content and the last compiled content
16
16
  is now written to `output.diff`
17
+ * Assigns, such as `@items`, `@layouts`, `@item`, … are accessible without `@`
17
18
 
18
19
  Changed:
19
20
 
data/README.md CHANGED
@@ -2,54 +2,50 @@
2
2
 
3
3
  nanoc is a simple but very flexible static site generator written in Ruby.
4
4
  It operates on local files, and therefore does not run on the server. nanoc
5
- "compiles" the local source files into HTML (usually), by evaluating eRuby,
5
+ compiles the local source files into HTML (usually), by evaluating eRuby,
6
6
  Markdown, etc.
7
7
 
8
- ## Documentation
8
+ ## Resources
9
9
 
10
- The [nanoc3 web site](http://nanoc.stoneship.org) contains a few useful
10
+ The [nanoc web site](http://nanoc.stoneship.org) contains a few useful
11
11
  resources to help you get started with nanoc:
12
12
 
13
13
  * The [tutorial](http://nanoc.stoneship.org/tutorial)
14
14
  * The [manual](http://nanoc.stoneship.org/manual)
15
15
  * The [migration guide](http://nanoc.stoneship.org/migrating)
16
16
 
17
- It is probably also worth checking out and perhaps subscribing to the
18
- discussion groups:
17
+ If you need assistance, the following places will help you out:
19
18
 
20
- * The [discussion group in English](http://groups.google.com/group/nanoc)
21
- * The [discussion group in Spanish](http://groups.google.com/group/nanoc-es)
19
+ * The [discussion group](http://groups.google.com/group/nanoc)
20
+ * The [IRC channel](irc://chat.freenode.net/#nanoc)
22
21
 
23
- ### Source Code Documentation
22
+ ## Source Code Documentation
24
23
 
25
- The source code is structured in a few directories:
24
+ The source code is located in `lib/nanoc3` and is structured in a few
25
+ directories:
26
26
 
27
- * `bin` contains the commandline tool aptly named `nanoc3`
28
- * `lib`
29
- * `nanoc3`
30
- * `base` contains the bare essentials necessary for nanoc to function
31
- * `cli` contains the commandline interface
32
- * `data_sources` contains the standard data sources (Nanoc3::DataSource
33
- subclasses), such as the filesystem data source
34
- * `helpers` contains helpers, which provide functionality some sites
35
- may find useful, such as the blogging and tagging helpers
36
- * `extra` contains stuff that is not needed by nanoc itself, but which may
37
- be used by helpers, data sources, filters or VCSes.
38
- * `filters` contains the standard filters (Nanoc3::Filter subclasses) such
39
- as ERB, Markdown, Haml, ...
40
- * `test` contains testing code, structured in the same way as lib/nanoc
27
+ * `base` contains the bare essentials necessary for nanoc to function
28
+ * `cli` contains the commandline interface
29
+ * `data_sources` contains the standard data sources ({Nanoc3::DataSource}
30
+ subclasses), such as the filesystem data source
31
+ * `helpers` contains helpers, which provide functionality some sites
32
+ may find useful, such as the blogging and tagging helpers
33
+ * `extra` contains stuff that is not needed by nanoc itself, but which may
34
+ be used by helpers, data sources, filters or VCSes.
35
+ * `filters` contains the standard filters ({Nanoc3::Filter} subclasses)
36
+ such as ERB, Markdown, Haml, ...
41
37
 
42
38
  The namespaces (modules) are organised like this:
43
39
 
44
- * `Nanoc3` is the namespace for everything nanoc-related (obviously). The
40
+ * {Nanoc3} is the namespace for everything nanoc-related (obviously). The
45
41
  classes in `lib/nanoc3/base` are part of this module (not `Nanoc3::Base`)
46
- * `CLI` containing everything related to the commandline tool.
47
- * `DataSources` contains the data sources
48
- * `Helpers` contains the helpers
49
- * `Extra` contains useful stuff not needed by nanoc itself
50
- * `Filters` contains the (textual) filters
42
+ * {Nanoc3::CLI} containing everything related to the commandline tool.
43
+ * {Nanoc3::DataSources} contains the data sources
44
+ * {Nanoc3::Helpers} contains the helpers
45
+ * {Nanoc3::Extra} contains useful stuff not needed by nanoc itself
46
+ * {Nanoc3::Filters} contains the (textual) filters
51
47
 
52
- The central class in nanoc is `Nanoc3::Site`, so you should start there if
48
+ The central class in nanoc is {Nanoc3::Site}, so you should start there if
53
49
  you want to explore nanoc from a technical perspective.
54
50
 
55
51
  ## Dependencies
@@ -74,7 +70,7 @@ components, however, do have dependencies:
74
70
  * Nicky Peeters
75
71
  * Christian Plessl
76
72
  * Šime Ramov
77
- * "Soryu"
73
+ * Soryu
78
74
  * Eric Sunshine
79
75
  * Dennis Sutch
80
76
 
@@ -2,7 +2,9 @@
2
2
 
3
3
  module Nanoc3::ArrayExtensions
4
4
 
5
- # Returns a new array where all items' keys are recursively converted to symbols by calling #symbolize_keys.
5
+ # Returns a new array where all items' keys are recursively converted to
6
+ # symbols by calling {Nanoc3::ArrayExtensions#symbolize_keys} or
7
+ # {Nanoc3::HashExtensions#symbolize_keys}.
6
8
  #
7
9
  # @return [Array] The converted array
8
10
  def symbolize_keys
@@ -11,7 +13,9 @@ module Nanoc3::ArrayExtensions
11
13
  end
12
14
  end
13
15
 
14
- # Returns a new array where all items' keys are recursively converted to strings by calling #stringify_keys.
16
+ # Returns a new array where all items' keys are recursively converted to
17
+ # strings by calling {Nanoc3::ArrayExtensions#stringify_keys} or
18
+ # {Nanoc3::HashExtensions#stringify_keys}.
15
19
  #
16
20
  # @return [Array] The converted array
17
21
  def stringify_keys
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::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
+
37
+ if !Enumerable.instance_methods.include?('group_by')
38
+ include Nanoc3::EnumerableExtensions::GroupBy
39
+ end
40
+
41
+ end
@@ -2,7 +2,9 @@
2
2
 
3
3
  module Nanoc3::HashExtensions
4
4
 
5
- # Returns a new hash where all keys are recursively converted to symbols.
5
+ # Returns a new hash where all keys are recursively converted to symbols by
6
+ # calling {Nanoc3::ArrayExtensions#symbolize_keys} or
7
+ # {Nanoc3::HashExtensions#symbolize_keys}.
6
8
  #
7
9
  # @return [Hash] The converted hash
8
10
  def symbolize_keys
@@ -11,7 +13,9 @@ module Nanoc3::HashExtensions
11
13
  end
12
14
  end
13
15
 
14
- # Returns a new hash where all keys are recursively converted to strings.
16
+ # Returns a new hash where all keys are recursively converted to strings by
17
+ # calling {Nanoc3::ArrayExtensions#stringify_keys} or
18
+ # {Nanoc3::HashExtensions#stringify_keys}.
15
19
  #
16
20
  # @return [Hash] The converted hash
17
21
  def stringify_keys
@@ -11,6 +11,7 @@ module Nanoc3
11
11
  # for setting identifiers, registering plugins and finding plugins. Plugin
12
12
  # classes should extend this module.
13
13
  module PluginMethods
14
+
14
15
  # Sets the identifiers for this plugin.
15
16
  #
16
17
  # @param [Array<Symbol>] identifier A list of identifiers to assign to
@@ -40,7 +41,13 @@ module Nanoc3
40
41
  #
41
42
  # @return [void]
42
43
  def register(class_or_name, *identifiers)
43
- Nanoc3::Plugin.register(self, class_or_name, *identifiers)
44
+ # Find plugin class
45
+ klass = self
46
+ klass = klass.superclass while klass.superclass.respond_to?(:register)
47
+
48
+ # Register
49
+ registry = Nanoc3::PluginRegistry.instance
50
+ registry.register(klass, class_or_name, *identifiers)
44
51
  end
45
52
 
46
53
  # Returns the plugin with the given name (identifier)
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
- module Nanoc3::Extra::EnumerableExtensions
3
+ module Enumerable
4
4
 
5
- module GroupBy
5
+ if !Enumerable.instance_methods.include?('group_by')
6
6
 
7
7
  # Returns a hash, which keys are evaluated result from the block, and
8
8
  # values are arrays of elements in enum corresponding to the key. This
@@ -31,9 +31,3 @@ module Nanoc3::Extra::EnumerableExtensions
31
31
  end
32
32
 
33
33
  end
34
-
35
- module Enumerable
36
- if !Enumerable.instance_methods.include?('group_by')
37
- include Nanoc3::Extra::EnumerableExtensions::GroupBy
38
- end
39
- end
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::Filters
4
+ class ColorizeSyntax < Nanoc3::Filter
5
+
6
+ DEFAULT_COLORIZER = :coderay
7
+
8
+ def run(content, params={})
9
+ require 'nokogiri'
10
+
11
+ # Take colorizers from parameters
12
+ @colorizers = Hash.new(DEFAULT_COLORIZER)
13
+ (params[:colorizers] || {}).each_pair do |language, colorizer|
14
+ @colorizers[language] = colorizer
15
+ end
16
+
17
+ # Colorize
18
+ doc = Nokogiri::HTML.fragment(content)
19
+ doc.css('pre > code[class^="lang"]').each do |element|
20
+ language = element['class'][/lang-([^ ]+)/].sub(/^lang-/, '')
21
+ element.parent.replace(
22
+ Nokogiri.make(highlight(element.inner_text, language, params))
23
+ )
24
+ end
25
+
26
+ doc.to_s
27
+ end
28
+
29
+ private
30
+
31
+ KNOWN_COLORIZERS = [ :coderay, :dummy, :pygmentize ]
32
+
33
+ def highlight(code, language, params={})
34
+ colorizer = @colorizers[language]
35
+ if KNOWN_COLORIZERS.include?(colorizer)
36
+ send(colorizer, code, language, params[colorizer])
37
+ else
38
+ raise RuntimeError, "I don’t know how to highlight code using the “#{colorizer}” colorizer"
39
+ end
40
+ end
41
+
42
+ def coderay(code, language, params={})
43
+ require 'coderay'
44
+
45
+ CodeRay.scan(code, language).div(params)
46
+ end
47
+
48
+ def dummy(code, language, params={})
49
+ code
50
+ end
51
+
52
+ def pygmentize(code, language, params={})
53
+ IO.popen("pygmentize -l #{language} -f html", "r+") do |io|
54
+ io.write(code)
55
+ io.close_write
56
+ return io.read
57
+ end
58
+ end
59
+
60
+ end
61
+ end
@@ -4,6 +4,7 @@ module Nanoc3::Filters
4
4
 
5
5
  autoload 'BlueCloth', 'nanoc3/filters/bluecloth'
6
6
  autoload 'CodeRay', 'nanoc3/filters/coderay'
7
+ autoload 'ColorizeSyntax', 'nanoc3/filters/colorize_syntax'
7
8
  autoload 'ERB', 'nanoc3/filters/erb'
8
9
  autoload 'Erubis', 'nanoc3/filters/erubis'
9
10
  autoload 'Haml', 'nanoc3/filters/haml'
@@ -21,6 +22,7 @@ module Nanoc3::Filters
21
22
 
22
23
  Nanoc3::Filter.register '::Nanoc3::Filters::BlueCloth', :bluecloth
23
24
  Nanoc3::Filter.register '::Nanoc3::Filters::CodeRay', :coderay
25
+ Nanoc3::Filter.register '::Nanoc3::Filters::ColorizeSyntax', :colorize_syntax
24
26
  Nanoc3::Filter.register '::Nanoc3::Filters::ERB', :erb
25
27
  Nanoc3::Filter.register '::Nanoc3::Filters::Erubis', :erubis
26
28
  Nanoc3::Filter.register '::Nanoc3::Filters::Haml', :haml
data/lib/nanoc3.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Nanoc3
4
4
 
5
5
  # The current nanoc version.
6
- VERSION = '3.1.0a1'
6
+ VERSION = '3.1.0a2'
7
7
 
8
8
  # Loads all nanoc3 plugins, i.e. requires all ruby gems whose name start
9
9
  # with `nanoc3-`.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc3
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0a1
4
+ version: 3.1.0a2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-15 00:00:00 +01:00
12
+ date: 2010-02-20 00:00:00 +01:00
13
13
  default_executable: nanoc3
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -44,6 +44,7 @@ files:
44
44
  - lib/nanoc3/base/compiler_dsl.rb
45
45
  - lib/nanoc3/base/context.rb
46
46
  - lib/nanoc3/base/core_ext/array.rb
47
+ - lib/nanoc3/base/core_ext/enumerable.rb
47
48
  - lib/nanoc3/base/core_ext/hash.rb
48
49
  - lib/nanoc3/base/core_ext/string.rb
49
50
  - lib/nanoc3/base/core_ext.rb
@@ -104,6 +105,7 @@ files:
104
105
  - lib/nanoc3/extra.rb
105
106
  - lib/nanoc3/filters/bluecloth.rb
106
107
  - lib/nanoc3/filters/coderay.rb
108
+ - lib/nanoc3/filters/colorize_syntax.rb
107
109
  - lib/nanoc3/filters/erb.rb
108
110
  - lib/nanoc3/filters/erubis.rb
109
111
  - lib/nanoc3/filters/haml.rb