nanoc 3.2.4 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/ChangeLog +3 -0
- data/Gemfile +32 -0
- data/LICENSE +19 -0
- data/NEWS.md +470 -0
- data/README.md +114 -0
- data/Rakefile +14 -0
- data/bin/nanoc +7 -27
- data/bin/nanoc3 +3 -0
- data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
- data/lib/nanoc.rb +41 -0
- data/lib/nanoc/base.rb +49 -0
- data/lib/nanoc/base/compilation/checksum_store.rb +57 -0
- data/lib/nanoc/base/compilation/compiled_content_cache.rb +62 -0
- data/lib/nanoc/base/compilation/compiler.rb +458 -0
- data/lib/nanoc/base/compilation/compiler_dsl.rb +214 -0
- data/lib/nanoc/base/compilation/dependency_tracker.rb +200 -0
- data/lib/nanoc/base/compilation/filter.rb +165 -0
- data/lib/nanoc/base/compilation/item_rep_proxy.rb +103 -0
- data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +102 -0
- data/lib/nanoc/base/compilation/outdatedness_checker.rb +223 -0
- data/lib/nanoc/base/compilation/outdatedness_reasons.rb +46 -0
- data/lib/nanoc/base/compilation/rule.rb +73 -0
- data/lib/nanoc/base/compilation/rule_context.rb +84 -0
- data/lib/nanoc/base/compilation/rule_memory_calculator.rb +40 -0
- data/lib/nanoc/base/compilation/rule_memory_store.rb +53 -0
- data/lib/nanoc/base/compilation/rules_collection.rb +243 -0
- data/lib/nanoc/base/context.rb +47 -0
- data/lib/nanoc/base/core_ext.rb +6 -0
- data/lib/nanoc/base/core_ext/array.rb +62 -0
- data/lib/nanoc/base/core_ext/hash.rb +63 -0
- data/lib/nanoc/base/core_ext/pathname.rb +26 -0
- data/lib/nanoc/base/core_ext/string.rb +46 -0
- data/lib/nanoc/base/directed_graph.rb +275 -0
- data/lib/nanoc/base/errors.rb +211 -0
- data/lib/nanoc/base/memoization.rb +67 -0
- data/lib/nanoc/base/notification_center.rb +84 -0
- data/lib/nanoc/base/ordered_hash.rb +200 -0
- data/lib/nanoc/base/plugin_registry.rb +181 -0
- data/lib/nanoc/base/result_data/item_rep.rb +492 -0
- data/lib/nanoc/base/source_data/code_snippet.rb +58 -0
- data/lib/nanoc/base/source_data/configuration.rb +24 -0
- data/lib/nanoc/base/source_data/data_source.rb +234 -0
- data/lib/nanoc/base/source_data/item.rb +301 -0
- data/lib/nanoc/base/source_data/layout.rb +130 -0
- data/lib/nanoc/base/source_data/site.rb +361 -0
- data/lib/nanoc/base/store.rb +135 -0
- data/lib/nanoc/cli.rb +137 -0
- data/lib/nanoc/cli/command_runner.rb +104 -0
- data/lib/nanoc/cli/commands/autocompile.rb +58 -0
- data/lib/nanoc/cli/commands/compile.rb +297 -0
- data/lib/nanoc/cli/commands/create_item.rb +60 -0
- data/lib/nanoc/cli/commands/create_layout.rb +73 -0
- data/lib/nanoc/cli/commands/create_site.rb +411 -0
- data/lib/nanoc/cli/commands/debug.rb +117 -0
- data/lib/nanoc/cli/commands/deploy.rb +79 -0
- data/lib/nanoc/cli/commands/info.rb +98 -0
- data/lib/nanoc/cli/commands/nanoc.rb +38 -0
- data/lib/nanoc/cli/commands/prune.rb +50 -0
- data/lib/nanoc/cli/commands/update.rb +70 -0
- data/lib/nanoc/cli/commands/view.rb +82 -0
- data/lib/nanoc/cli/commands/watch.rb +124 -0
- data/lib/nanoc/cli/error_handler.rb +199 -0
- data/lib/nanoc/cli/logger.rb +92 -0
- data/lib/nanoc/data_sources.rb +29 -0
- data/lib/nanoc/data_sources/deprecated/delicious.rb +42 -0
- data/lib/nanoc/data_sources/deprecated/last_fm.rb +87 -0
- data/lib/nanoc/data_sources/deprecated/twitter.rb +38 -0
- data/lib/nanoc/data_sources/filesystem.rb +299 -0
- data/lib/nanoc/data_sources/filesystem_unified.rb +121 -0
- data/lib/nanoc/data_sources/filesystem_verbose.rb +91 -0
- data/lib/nanoc/extra.rb +24 -0
- data/lib/nanoc/extra/auto_compiler.rb +103 -0
- data/lib/nanoc/extra/chick.rb +125 -0
- data/lib/nanoc/extra/core_ext.rb +6 -0
- data/lib/nanoc/extra/core_ext/enumerable.rb +33 -0
- data/lib/nanoc/extra/core_ext/pathname.rb +30 -0
- data/lib/nanoc/extra/core_ext/time.rb +19 -0
- data/lib/nanoc/extra/deployer.rb +47 -0
- data/lib/nanoc/extra/deployers.rb +15 -0
- data/lib/nanoc/extra/deployers/fog.rb +98 -0
- data/lib/nanoc/extra/deployers/rsync.rb +70 -0
- data/lib/nanoc/extra/file_proxy.rb +40 -0
- data/lib/nanoc/extra/pruner.rb +86 -0
- data/lib/nanoc/extra/validators.rb +12 -0
- data/lib/nanoc/extra/validators/links.rb +268 -0
- data/lib/nanoc/extra/validators/w3c.rb +95 -0
- data/lib/nanoc/extra/vcs.rb +66 -0
- data/lib/nanoc/extra/vcses.rb +17 -0
- data/lib/nanoc/extra/vcses/bazaar.rb +25 -0
- data/lib/nanoc/extra/vcses/dummy.rb +24 -0
- data/lib/nanoc/extra/vcses/git.rb +25 -0
- data/lib/nanoc/extra/vcses/mercurial.rb +25 -0
- data/lib/nanoc/extra/vcses/subversion.rb +25 -0
- data/lib/nanoc/filters.rb +59 -0
- data/lib/nanoc/filters/asciidoc.rb +38 -0
- data/lib/nanoc/filters/bluecloth.rb +19 -0
- data/lib/nanoc/filters/coderay.rb +21 -0
- data/lib/nanoc/filters/coffeescript.rb +20 -0
- data/lib/nanoc/filters/colorize_syntax.rb +298 -0
- data/lib/nanoc/filters/erb.rb +38 -0
- data/lib/nanoc/filters/erubis.rb +34 -0
- data/lib/nanoc/filters/haml.rb +27 -0
- data/lib/nanoc/filters/kramdown.rb +20 -0
- data/lib/nanoc/filters/less.rb +53 -0
- data/lib/nanoc/filters/markaby.rb +20 -0
- data/lib/nanoc/filters/maruku.rb +20 -0
- data/lib/nanoc/filters/mustache.rb +24 -0
- data/lib/nanoc/filters/rainpress.rb +19 -0
- data/lib/nanoc/filters/rdiscount.rb +22 -0
- data/lib/nanoc/filters/rdoc.rb +33 -0
- data/lib/nanoc/filters/redcarpet.rb +62 -0
- data/lib/nanoc/filters/redcloth.rb +47 -0
- data/lib/nanoc/filters/relativize_paths.rb +94 -0
- data/lib/nanoc/filters/rubypants.rb +20 -0
- data/lib/nanoc/filters/sass.rb +74 -0
- data/lib/nanoc/filters/slim.rb +25 -0
- data/lib/nanoc/filters/typogruby.rb +23 -0
- data/lib/nanoc/filters/uglify_js.rb +42 -0
- data/lib/nanoc/filters/xsl.rb +46 -0
- data/lib/nanoc/filters/yui_compressor.rb +23 -0
- data/lib/nanoc/helpers.rb +16 -0
- data/lib/nanoc/helpers/blogging.rb +319 -0
- data/lib/nanoc/helpers/breadcrumbs.rb +40 -0
- data/lib/nanoc/helpers/capturing.rb +138 -0
- data/lib/nanoc/helpers/filtering.rb +50 -0
- data/lib/nanoc/helpers/html_escape.rb +55 -0
- data/lib/nanoc/helpers/link_to.rb +151 -0
- data/lib/nanoc/helpers/rendering.rb +140 -0
- data/lib/nanoc/helpers/tagging.rb +71 -0
- data/lib/nanoc/helpers/text.rb +44 -0
- data/lib/nanoc/helpers/xml_sitemap.rb +76 -0
- data/lib/nanoc/tasks.rb +10 -0
- data/lib/nanoc/tasks/clean.rake +16 -0
- data/lib/nanoc/tasks/clean.rb +29 -0
- data/lib/nanoc/tasks/deploy/rsync.rake +16 -0
- data/lib/nanoc/tasks/validate.rake +92 -0
- data/nanoc.gemspec +49 -0
- data/tasks/doc.rake +16 -0
- data/tasks/test.rake +46 -0
- data/test/base/core_ext/array_spec.rb +73 -0
- data/test/base/core_ext/hash_spec.rb +98 -0
- data/test/base/core_ext/pathname_spec.rb +27 -0
- data/test/base/core_ext/string_spec.rb +37 -0
- data/test/base/test_checksum_store.rb +35 -0
- data/test/base/test_code_snippet.rb +31 -0
- data/test/base/test_compiler.rb +403 -0
- data/test/base/test_compiler_dsl.rb +161 -0
- data/test/base/test_context.rb +31 -0
- data/test/base/test_data_source.rb +46 -0
- data/test/base/test_dependency_tracker.rb +262 -0
- data/test/base/test_directed_graph.rb +288 -0
- data/test/base/test_filter.rb +83 -0
- data/test/base/test_item.rb +179 -0
- data/test/base/test_item_rep.rb +579 -0
- data/test/base/test_layout.rb +59 -0
- data/test/base/test_memoization.rb +90 -0
- data/test/base/test_notification_center.rb +34 -0
- data/test/base/test_outdatedness_checker.rb +394 -0
- data/test/base/test_plugin.rb +30 -0
- data/test/base/test_rule.rb +19 -0
- data/test/base/test_rule_context.rb +65 -0
- data/test/base/test_site.rb +190 -0
- data/test/cli/commands/test_compile.rb +33 -0
- data/test/cli/commands/test_create_item.rb +14 -0
- data/test/cli/commands/test_create_layout.rb +28 -0
- data/test/cli/commands/test_create_site.rb +24 -0
- data/test/cli/commands/test_deploy.rb +74 -0
- data/test/cli/commands/test_help.rb +12 -0
- data/test/cli/commands/test_info.rb +11 -0
- data/test/cli/commands/test_prune.rb +98 -0
- data/test/cli/commands/test_update.rb +10 -0
- data/test/cli/test_cli.rb +102 -0
- data/test/cli/test_error_handler.rb +29 -0
- data/test/cli/test_logger.rb +10 -0
- data/test/data_sources/test_filesystem.rb +433 -0
- data/test/data_sources/test_filesystem_unified.rb +536 -0
- data/test/data_sources/test_filesystem_verbose.rb +357 -0
- data/test/extra/core_ext/test_enumerable.rb +30 -0
- data/test/extra/core_ext/test_pathname.rb +17 -0
- data/test/extra/core_ext/test_time.rb +15 -0
- data/test/extra/deployers/test_fog.rb +67 -0
- data/test/extra/deployers/test_rsync.rb +100 -0
- data/test/extra/test_auto_compiler.rb +417 -0
- data/test/extra/test_file_proxy.rb +19 -0
- data/test/extra/test_vcs.rb +22 -0
- data/test/extra/validators/test_links.rb +62 -0
- data/test/extra/validators/test_w3c.rb +47 -0
- data/test/filters/test_asciidoc.rb +22 -0
- data/test/filters/test_bluecloth.rb +18 -0
- data/test/filters/test_coderay.rb +44 -0
- data/test/filters/test_coffeescript.rb +18 -0
- data/test/filters/test_colorize_syntax.rb +379 -0
- data/test/filters/test_erb.rb +105 -0
- data/test/filters/test_erubis.rb +78 -0
- data/test/filters/test_haml.rb +96 -0
- data/test/filters/test_kramdown.rb +18 -0
- data/test/filters/test_less.rb +113 -0
- data/test/filters/test_markaby.rb +24 -0
- data/test/filters/test_maruku.rb +18 -0
- data/test/filters/test_mustache.rb +25 -0
- data/test/filters/test_rainpress.rb +29 -0
- data/test/filters/test_rdiscount.rb +31 -0
- data/test/filters/test_rdoc.rb +18 -0
- data/test/filters/test_redcarpet.rb +73 -0
- data/test/filters/test_redcloth.rb +33 -0
- data/test/filters/test_relativize_paths.rb +533 -0
- data/test/filters/test_rubypants.rb +18 -0
- data/test/filters/test_sass.rb +229 -0
- data/test/filters/test_slim.rb +35 -0
- data/test/filters/test_typogruby.rb +21 -0
- data/test/filters/test_uglify_js.rb +30 -0
- data/test/filters/test_xsl.rb +105 -0
- data/test/filters/test_yui_compressor.rb +44 -0
- data/test/gem_loader.rb +11 -0
- data/test/helper.rb +207 -0
- data/test/helpers/test_blogging.rb +754 -0
- data/test/helpers/test_breadcrumbs.rb +81 -0
- data/test/helpers/test_capturing.rb +41 -0
- data/test/helpers/test_filtering.rb +106 -0
- data/test/helpers/test_html_escape.rb +32 -0
- data/test/helpers/test_link_to.rb +249 -0
- data/test/helpers/test_rendering.rb +89 -0
- data/test/helpers/test_tagging.rb +87 -0
- data/test/helpers/test_text.rb +24 -0
- data/test/helpers/test_xml_sitemap.rb +103 -0
- data/test/tasks/test_clean.rb +67 -0
- metadata +327 -15
- data/bin/nanoc-select +0 -86
- data/lib/nanoc-select.rb +0 -11
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
class ERB < Nanoc::Filter
|
7
|
+
|
8
|
+
# Runs the content through [ERB](http://ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html).
|
9
|
+
#
|
10
|
+
# @param [String] content The content to filter
|
11
|
+
#
|
12
|
+
# @option params [Integer] safe_level (nil) The safe level (`$SAFE`) to
|
13
|
+
# use while running this filter
|
14
|
+
#
|
15
|
+
# @option params [String] trim_mode (nil) The trim mode to use
|
16
|
+
#
|
17
|
+
# @return [String] The filtered content
|
18
|
+
def run(content, params={})
|
19
|
+
# Add locals
|
20
|
+
assigns.merge!(params[:locals] || {})
|
21
|
+
|
22
|
+
# Create context
|
23
|
+
context = ::Nanoc::Context.new(assigns)
|
24
|
+
|
25
|
+
# Get binding
|
26
|
+
proc = assigns[:content] ? lambda { assigns[:content] } : nil
|
27
|
+
assigns_binding = context.get_binding(&proc)
|
28
|
+
|
29
|
+
# Get result
|
30
|
+
safe_level = params[:safe_level]
|
31
|
+
trim_mode = params[:trim_mode]
|
32
|
+
erb = ::ERB.new(content, safe_level, trim_mode)
|
33
|
+
erb.filename = filename
|
34
|
+
erb.result(assigns_binding)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'erubis'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
class Erubis < Nanoc::Filter
|
7
|
+
|
8
|
+
# The same as `::Erubis::Eruby` but adds `_erbout` as an alias for the
|
9
|
+
# `_buf` variable, making it compatible with nanoc’s helpers that rely
|
10
|
+
# on `_erbout`, such as {Nanoc::Helpers::Capturing}.
|
11
|
+
class ErubisWithErbout < ::Erubis::Eruby
|
12
|
+
include ::Erubis::ErboutEnhancer
|
13
|
+
end
|
14
|
+
|
15
|
+
# Runs the content through [Erubis](http://www.kuwata-lab.com/erubis/).
|
16
|
+
# This method takes no options.
|
17
|
+
#
|
18
|
+
# @param [String] content The content to filter
|
19
|
+
#
|
20
|
+
# @return [String] The filtered content
|
21
|
+
def run(content, params={})
|
22
|
+
# Create context
|
23
|
+
context = ::Nanoc::Context.new(assigns)
|
24
|
+
|
25
|
+
# Get binding
|
26
|
+
proc = assigns[:content] ? lambda { assigns[:content] } : nil
|
27
|
+
assigns_binding = context.get_binding(&proc)
|
28
|
+
|
29
|
+
# Get result
|
30
|
+
ErubisWithErbout.new(content, :filename => filename).result(assigns_binding)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'haml'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
class Haml < Nanoc::Filter
|
7
|
+
|
8
|
+
# Runs the content through [Haml](http://haml-lang.com/).
|
9
|
+
# Parameters passed to this filter will be passed on to Haml.
|
10
|
+
#
|
11
|
+
# @param [String] content The content to filter
|
12
|
+
#
|
13
|
+
# @return [String] The filtered content
|
14
|
+
def run(content, params={})
|
15
|
+
# Get options
|
16
|
+
options = params.merge(:filename => filename)
|
17
|
+
|
18
|
+
# Create context
|
19
|
+
context = ::Nanoc::Context.new(assigns)
|
20
|
+
|
21
|
+
# Get result
|
22
|
+
proc = assigns[:content] ? lambda { assigns[:content] } : nil
|
23
|
+
::Haml::Engine.new(content, options).render(context, assigns, &proc)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'kramdown'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
class Kramdown < Nanoc::Filter
|
7
|
+
|
8
|
+
# Runs the content through [Kramdown](http://kramdown.rubyforge.org/).
|
9
|
+
# Parameters passed to this filter will be passed on to Kramdown.
|
10
|
+
#
|
11
|
+
# @param [String] content The content to filter
|
12
|
+
#
|
13
|
+
# @return [String] The filtered content
|
14
|
+
def run(content, params={})
|
15
|
+
# Get result
|
16
|
+
::Kramdown::Document.new(content, params).to_html
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'less'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
class Less < Nanoc::Filter
|
7
|
+
|
8
|
+
# Runs the content through [LESS](http://lesscss.org/).
|
9
|
+
# This method takes no options.
|
10
|
+
#
|
11
|
+
# @param [String] content The content to filter
|
12
|
+
#
|
13
|
+
# @return [String] The filtered content
|
14
|
+
def run(content, params={})
|
15
|
+
# Find imports (hacky)
|
16
|
+
imports = []
|
17
|
+
imports.concat(content.scan(/^@import\s+(["'])([^\1]+?)\1;/))
|
18
|
+
imports.concat(content.scan(/^@import\s+url\((["']?)([^)]+?)\1\);/))
|
19
|
+
imported_filenames = imports.map do |i|
|
20
|
+
i[1].match(/\.(less|css)$/) ? i[1] : i[1] + '.less'
|
21
|
+
end
|
22
|
+
|
23
|
+
# Convert to items
|
24
|
+
imported_items = imported_filenames.map do |filename|
|
25
|
+
# Find directory for this item
|
26
|
+
current_dir_pathname = Pathname.new(@item[:content_filename]).dirname.realpath
|
27
|
+
|
28
|
+
# Find absolute pathname for imported item
|
29
|
+
imported_pathname = Pathname.new(filename)
|
30
|
+
if imported_pathname.relative?
|
31
|
+
imported_pathname = current_dir_pathname + imported_pathname
|
32
|
+
end
|
33
|
+
next if !imported_pathname.exist?
|
34
|
+
imported_filename = imported_pathname.realpath
|
35
|
+
|
36
|
+
# Find matching item
|
37
|
+
@items.find do |i|
|
38
|
+
next if i[:content_filename].nil?
|
39
|
+
Pathname.new(i[:content_filename]).realpath == imported_filename
|
40
|
+
end
|
41
|
+
end.compact
|
42
|
+
|
43
|
+
# Create dependencies
|
44
|
+
depend_on(imported_items)
|
45
|
+
|
46
|
+
# Add filename to load path
|
47
|
+
paths = [ File.dirname(@item[:content_filename]) ]
|
48
|
+
parser = ::Less::Parser.new(:paths => paths)
|
49
|
+
parser.parse(content).to_css
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'markaby'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
class Markaby < Nanoc::Filter
|
7
|
+
|
8
|
+
# Runs the content through [Markaby](http://markaby.rubyforge.org/).
|
9
|
+
# This method takes no options.
|
10
|
+
#
|
11
|
+
# @param [String] content The content to filter
|
12
|
+
#
|
13
|
+
# @return [String] The filtered content
|
14
|
+
def run(content, params={})
|
15
|
+
# Get result
|
16
|
+
::Markaby::Builder.new(assigns).instance_eval(content).to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'maruku'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
class Maruku < Nanoc::Filter
|
7
|
+
|
8
|
+
# Runs the content through [Maruku](http://maruku.rubyforge.org/).
|
9
|
+
# Parameters passed to this filter will be passed on to Maruku.
|
10
|
+
#
|
11
|
+
# @param [String] content The content to filter
|
12
|
+
#
|
13
|
+
# @return [String] The filtered content
|
14
|
+
def run(content, params={})
|
15
|
+
# Get result
|
16
|
+
::Maruku.new(content, params).to_html
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'mustache'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
|
7
|
+
# @since 3.2.0
|
8
|
+
class Mustache < Nanoc::Filter
|
9
|
+
|
10
|
+
# Runs the content through
|
11
|
+
# [Mustache](http://github.com/defunkt/mustache). This method takes no
|
12
|
+
# options.
|
13
|
+
#
|
14
|
+
# @param [String] content The content to filter
|
15
|
+
#
|
16
|
+
# @return [String] The filtered content
|
17
|
+
def run(content, params={})
|
18
|
+
# Get result
|
19
|
+
::Mustache.render(content, item.attributes)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rainpress'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
class Rainpress < Nanoc::Filter
|
7
|
+
|
8
|
+
# Runs the content through [Rainpress](http://code.google.com/p/rainpress/).
|
9
|
+
# Parameters passed to this filter will be passed on to Rainpress.
|
10
|
+
#
|
11
|
+
# @param [String] content The content to filter
|
12
|
+
#
|
13
|
+
# @return [String] The filtered content
|
14
|
+
def run(content, params={})
|
15
|
+
::Rainpress.compress(content, params)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rdiscount'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
class RDiscount < Nanoc::Filter
|
7
|
+
|
8
|
+
# Runs the content through [RDiscount](http://github.com/rtomayko/rdiscount).
|
9
|
+
#
|
10
|
+
# @option params [Array] symbol ([]) A list of RDiscount extensions
|
11
|
+
#
|
12
|
+
# @param [String] content The content to filter
|
13
|
+
#
|
14
|
+
# @return [String] The filtered content
|
15
|
+
def run(content, params={})
|
16
|
+
extensions = params[:extensions] || []
|
17
|
+
|
18
|
+
::RDiscount.new(content, *extensions).to_html
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
begin
|
4
|
+
# new RDoc
|
5
|
+
require 'rdoc/markup'
|
6
|
+
require 'rdoc/markup/to_html'
|
7
|
+
rescue LoadError
|
8
|
+
# old RDoc
|
9
|
+
require 'rdoc/markup/simple_markup'
|
10
|
+
require 'rdoc/markup/simple_markup/to_html'
|
11
|
+
end
|
12
|
+
|
13
|
+
module Nanoc::Filters
|
14
|
+
class RDoc < Nanoc::Filter
|
15
|
+
|
16
|
+
# Runs the content through [RDoc::Markup](http://rdoc.rubyforge.org/RDoc/Markup.html).
|
17
|
+
# This method takes no options.
|
18
|
+
#
|
19
|
+
# @param [String] content The content to filter
|
20
|
+
#
|
21
|
+
# @return [String] The filtered content
|
22
|
+
def run(content, params={})
|
23
|
+
begin
|
24
|
+
# new RDoc
|
25
|
+
::RDoc::Markup.new.convert(content, ::RDoc::Markup::ToHtml.new)
|
26
|
+
rescue LoadError
|
27
|
+
# old RDoc
|
28
|
+
::SM::SimpleMarkup.new.convert(content, ::SM::ToHtml.new)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'redcarpet'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
|
7
|
+
# @since 3.2.0
|
8
|
+
class Redcarpet < Nanoc::Filter
|
9
|
+
|
10
|
+
# Runs the content through [Redcarpet](https://github.com/tanoku/redcarpet/).
|
11
|
+
# This method optionally takes processing options to pass on to Redcarpet.
|
12
|
+
#
|
13
|
+
# @overload run(content, params={})
|
14
|
+
#
|
15
|
+
# For Redcarpet 1.x
|
16
|
+
#
|
17
|
+
# @param [String] content The content to filter
|
18
|
+
#
|
19
|
+
# @option params [Array] :options ([]) A list of options to pass on to
|
20
|
+
# Redcarpet
|
21
|
+
#
|
22
|
+
# @return [String] The filtered content
|
23
|
+
#
|
24
|
+
# @overload run(content, params={})
|
25
|
+
#
|
26
|
+
# For Redcarpet 2.x
|
27
|
+
#
|
28
|
+
# @since 3.2.4
|
29
|
+
#
|
30
|
+
# @param [String] content The content to filter
|
31
|
+
#
|
32
|
+
# @option params [Hash] :options ({}) A list of options to pass on to
|
33
|
+
# Redcarpet itself (not the renderer)
|
34
|
+
#
|
35
|
+
# @option params [::Redcarpet::Render::Base] :renderer
|
36
|
+
# (::Redcarpet::Render::HTML) The class of the renderer to use
|
37
|
+
#
|
38
|
+
# @option params [Hash] :renderer_options ({}) A list of options to pass
|
39
|
+
# on to the Redcarpet renderer
|
40
|
+
#
|
41
|
+
# @return [String] The filtered content
|
42
|
+
def run(content, params={})
|
43
|
+
if ::Redcarpet::VERSION > '2'
|
44
|
+
options = params[:options] || {}
|
45
|
+
renderer_class = params[:renderer] || ::Redcarpet::Render::HTML
|
46
|
+
renderer_options = params[:renderer_options] || {}
|
47
|
+
|
48
|
+
if options.is_a?(Array)
|
49
|
+
warn 'WARNING: You are passing an array of options to the :redcarpet filter, but Redcarpet 2.x expects a hash instead. This will likely fail.'
|
50
|
+
end
|
51
|
+
|
52
|
+
renderer = renderer_class.new(renderer_options)
|
53
|
+
::Redcarpet::Markdown.new(renderer, options).render(content)
|
54
|
+
else
|
55
|
+
options = params[:options] || []
|
56
|
+
::Redcarpet.new(content, *options).to_html
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'redcloth'
|
4
|
+
|
5
|
+
module Nanoc::Filters
|
6
|
+
class RedCloth < Nanoc::Filter
|
7
|
+
|
8
|
+
# Runs the content through [RedCloth](http://redcloth.org/). This method
|
9
|
+
# takes the following options:
|
10
|
+
#
|
11
|
+
# * `:filter_class`
|
12
|
+
# * `:filter_html`
|
13
|
+
# * `:filter_ids`
|
14
|
+
# * `:filter_style`
|
15
|
+
# * `:hard_breaks`
|
16
|
+
# * `:lite_mode`
|
17
|
+
# * `:no_span_caps`
|
18
|
+
# * `:sanitize_htm`
|
19
|
+
#
|
20
|
+
# Each of these options sets the corresponding attribute on the `RedCloth`
|
21
|
+
# instance. For example, when the `:hard_breaks => false` option is passed
|
22
|
+
# to this filter, the filter will call `r.hard_breaks = false` (with `r`
|
23
|
+
# being the `RedCloth` instance).
|
24
|
+
#
|
25
|
+
# @param [String] content The content to filter
|
26
|
+
#
|
27
|
+
# @return [String] The filtered content
|
28
|
+
def run(content, params={})
|
29
|
+
# Create formatter
|
30
|
+
r = ::RedCloth.new(content)
|
31
|
+
|
32
|
+
# Set options
|
33
|
+
r.filter_classes = params[:filter_classes] if params.has_key?(:filter_classes)
|
34
|
+
r.filter_html = params[:filter_html] if params.has_key?(:filter_html)
|
35
|
+
r.filter_ids = params[:filter_ids] if params.has_key?(:filter_ids)
|
36
|
+
r.filter_styles = params[:filter_styles] if params.has_key?(:filter_styles)
|
37
|
+
r.hard_breaks = params[:hard_breaks] if params.has_key?(:hard_breaks)
|
38
|
+
r.lite_mode = params[:lite_mode] if params.has_key?(:lite_mode)
|
39
|
+
r.no_span_caps = params[:no_span_caps] if params.has_key?(:no_span_caps)
|
40
|
+
r.sanitize_html = params[:sanitize_html] if params.has_key?(:sanitize_html)
|
41
|
+
|
42
|
+
# Get result
|
43
|
+
r.to_html
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Nanoc::Filters
|
4
|
+
class RelativizePaths < Nanoc::Filter
|
5
|
+
|
6
|
+
require 'nanoc/helpers/link_to'
|
7
|
+
include Nanoc::Helpers::LinkTo
|
8
|
+
|
9
|
+
SELECTORS = [ 'a/@href', 'img/@src', 'script/@src', 'link/@href' ]
|
10
|
+
|
11
|
+
# Relativizes all paths in the given content, which can be HTML, XHTML, XML
|
12
|
+
# or CSS. This filter is quite useful if a site needs to be hosted in a
|
13
|
+
# subdirectory instead of a subdomain. In HTML, all `href` and `src`
|
14
|
+
# attributes will be relativized. In CSS, all `url()` references will be
|
15
|
+
# relativized.
|
16
|
+
#
|
17
|
+
# @param [String] content The content to filter
|
18
|
+
#
|
19
|
+
# @option params [Symbol] :type The type of content to filter; can be
|
20
|
+
# `:html`, `:xhtml`, `:xml` or `:css`.
|
21
|
+
#
|
22
|
+
# @option params [Array] :select The XPath expressions that matches the
|
23
|
+
# nodes to modify. This param is useful only for the `:xml` and `:xhtml`
|
24
|
+
# types.
|
25
|
+
#
|
26
|
+
# @option params [Hash] :namespaces The pairs `prefix => uri` to define
|
27
|
+
# any namespace you want to use in the XPath expressions. This param
|
28
|
+
# is useful only for the `:xml` and `:xhtml` types.
|
29
|
+
#
|
30
|
+
# @return [String] The filtered content
|
31
|
+
def run(content, params={})
|
32
|
+
# Set assigns so helper function can be used
|
33
|
+
@item_rep = assigns[:item_rep] if @item_rep.nil?
|
34
|
+
|
35
|
+
# Filter
|
36
|
+
case params[:type]
|
37
|
+
when :html
|
38
|
+
# FIXME parse HTML the proper way using nokogiri
|
39
|
+
content.gsub(/(<[^>]+\s+(src|href))=(['"]?)(\/(?:[^\/].*?)?)\3([\s\/>])/) do
|
40
|
+
$1 + '=' + $3 + relative_path_to($4) + $3 + $5
|
41
|
+
end
|
42
|
+
when :css
|
43
|
+
# FIXME parse CSS the proper way using csspool or something
|
44
|
+
content.gsub(/url\((['"]?)(\/(?:[^\/].*?)?)\1\)/) do
|
45
|
+
'url(' + $1 + relative_path_to($2) + $1 + ')'
|
46
|
+
end
|
47
|
+
when :xml, :xhtml
|
48
|
+
selectors = params.fetch(:select) { SELECTORS }
|
49
|
+
namespaces = params[:namespaces] || {}
|
50
|
+
|
51
|
+
if params[:type] == :xhtml
|
52
|
+
# FIXME cleanup because it is ugly
|
53
|
+
# this cleans the XHTML namespace to process fragments and full
|
54
|
+
# documents in the same way. At least, Nokogiri adds this namespace
|
55
|
+
# if detects the `html` element.
|
56
|
+
content.sub!(%r{(<html[^>]+)xmlns="http://www.w3.org/1999/xhtml"}, '\1')
|
57
|
+
end
|
58
|
+
|
59
|
+
nokogiri_process(content, selectors, namespaces, params[:type])
|
60
|
+
else
|
61
|
+
raise RuntimeError.new(
|
62
|
+
"The relativize_paths needs to know the type of content to " +
|
63
|
+
"process. Pass a :type to the filter call (:html for HTML, " +
|
64
|
+
":xhtml for XHTML, :xml for XML, or :css for CSS).")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def nokogiri_process(content, selectors, namespaces, type)
|
71
|
+
require 'nokogiri'
|
72
|
+
|
73
|
+
# Ensure that all prefixes are strings
|
74
|
+
namespaces = namespaces.inject({}) { |new, (prefix, uri)| new.merge(prefix.to_s => uri) }
|
75
|
+
|
76
|
+
doc = ::Nokogiri::XML.fragment(content)
|
77
|
+
selectors.map { |sel| "descendant-or-self::#{sel}" }.each do |selector|
|
78
|
+
doc.xpath(selector, namespaces).each do |node|
|
79
|
+
node.content = relative_path_to(node.content)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
result = doc.send("to_#{type}")
|
83
|
+
|
84
|
+
# FIXME cleanup because it is ugly
|
85
|
+
# Because using the `Nokogiri::XML::DocumentFragment` class DOCTYPE
|
86
|
+
# pseudonodes becomes even more creepy than usual.
|
87
|
+
result.sub!(/(!DOCTYPE.+?)(>)/, '<\1>')
|
88
|
+
|
89
|
+
result
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|