nanoc3 3.2.4 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metadata +14 -313
- data/.gemtest +0 -0
- data/ChangeLog +0 -3
- data/Gemfile +0 -29
- data/LICENSE +0 -19
- data/NEWS.md +0 -449
- data/README.md +0 -108
- data/Rakefile +0 -14
- data/bin/nanoc3 +0 -12
- data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
- data/lib/nanoc3.rb +0 -28
- data/lib/nanoc3/base.rb +0 -49
- data/lib/nanoc3/base/compilation/checksum_store.rb +0 -57
- data/lib/nanoc3/base/compilation/compiled_content_cache.rb +0 -62
- data/lib/nanoc3/base/compilation/compiler.rb +0 -455
- data/lib/nanoc3/base/compilation/compiler_dsl.rb +0 -214
- data/lib/nanoc3/base/compilation/dependency_tracker.rb +0 -196
- data/lib/nanoc3/base/compilation/filter.rb +0 -165
- data/lib/nanoc3/base/compilation/item_rep_proxy.rb +0 -102
- data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +0 -88
- data/lib/nanoc3/base/compilation/outdatedness_checker.rb +0 -223
- data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +0 -46
- data/lib/nanoc3/base/compilation/rule.rb +0 -73
- data/lib/nanoc3/base/compilation/rule_context.rb +0 -84
- data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +0 -40
- data/lib/nanoc3/base/compilation/rule_memory_store.rb +0 -53
- data/lib/nanoc3/base/compilation/rules_collection.rb +0 -231
- data/lib/nanoc3/base/context.rb +0 -47
- data/lib/nanoc3/base/core_ext.rb +0 -6
- data/lib/nanoc3/base/core_ext/array.rb +0 -62
- data/lib/nanoc3/base/core_ext/hash.rb +0 -63
- data/lib/nanoc3/base/core_ext/pathname.rb +0 -26
- data/lib/nanoc3/base/core_ext/string.rb +0 -46
- data/lib/nanoc3/base/directed_graph.rb +0 -275
- data/lib/nanoc3/base/errors.rb +0 -174
- data/lib/nanoc3/base/memoization.rb +0 -67
- data/lib/nanoc3/base/notification_center.rb +0 -84
- data/lib/nanoc3/base/ordered_hash.rb +0 -200
- data/lib/nanoc3/base/plugin_registry.rb +0 -165
- data/lib/nanoc3/base/result_data/item_rep.rb +0 -488
- data/lib/nanoc3/base/source_data/code_snippet.rb +0 -58
- data/lib/nanoc3/base/source_data/configuration.rb +0 -24
- data/lib/nanoc3/base/source_data/data_source.rb +0 -234
- data/lib/nanoc3/base/source_data/item.rb +0 -301
- data/lib/nanoc3/base/source_data/layout.rb +0 -130
- data/lib/nanoc3/base/source_data/site.rb +0 -361
- data/lib/nanoc3/base/store.rb +0 -135
- data/lib/nanoc3/cli.rb +0 -133
- data/lib/nanoc3/cli/command.rb +0 -139
- data/lib/nanoc3/cli/commands/autocompile.rb +0 -60
- data/lib/nanoc3/cli/commands/compile.rb +0 -280
- data/lib/nanoc3/cli/commands/create_item.rb +0 -62
- data/lib/nanoc3/cli/commands/create_layout.rb +0 -75
- data/lib/nanoc3/cli/commands/create_site.rb +0 -410
- data/lib/nanoc3/cli/commands/debug.rb +0 -119
- data/lib/nanoc3/cli/commands/info.rb +0 -98
- data/lib/nanoc3/cli/commands/nanoc.rb +0 -37
- data/lib/nanoc3/cli/commands/update.rb +0 -72
- data/lib/nanoc3/cli/commands/view.rb +0 -84
- data/lib/nanoc3/cli/commands/watch.rb +0 -125
- data/lib/nanoc3/cli/error_handler.rb +0 -193
- data/lib/nanoc3/cli/logger.rb +0 -91
- data/lib/nanoc3/data_sources.rb +0 -29
- data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -42
- data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -87
- data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -38
- data/lib/nanoc3/data_sources/filesystem.rb +0 -299
- data/lib/nanoc3/data_sources/filesystem_unified.rb +0 -116
- data/lib/nanoc3/data_sources/filesystem_verbose.rb +0 -86
- data/lib/nanoc3/extra.rb +0 -22
- data/lib/nanoc3/extra/auto_compiler.rb +0 -103
- data/lib/nanoc3/extra/chick.rb +0 -125
- data/lib/nanoc3/extra/core_ext.rb +0 -4
- data/lib/nanoc3/extra/core_ext/enumerable.rb +0 -33
- data/lib/nanoc3/extra/core_ext/time.rb +0 -19
- data/lib/nanoc3/extra/deployers.rb +0 -11
- data/lib/nanoc3/extra/deployers/rsync.rb +0 -114
- data/lib/nanoc3/extra/file_proxy.rb +0 -40
- data/lib/nanoc3/extra/validators.rb +0 -12
- data/lib/nanoc3/extra/validators/links.rb +0 -264
- data/lib/nanoc3/extra/validators/w3c.rb +0 -95
- data/lib/nanoc3/extra/vcs.rb +0 -66
- data/lib/nanoc3/extra/vcses.rb +0 -17
- data/lib/nanoc3/extra/vcses/bazaar.rb +0 -25
- data/lib/nanoc3/extra/vcses/dummy.rb +0 -24
- data/lib/nanoc3/extra/vcses/git.rb +0 -25
- data/lib/nanoc3/extra/vcses/mercurial.rb +0 -25
- data/lib/nanoc3/extra/vcses/subversion.rb +0 -25
- data/lib/nanoc3/filters.rb +0 -53
- data/lib/nanoc3/filters/asciidoc.rb +0 -38
- data/lib/nanoc3/filters/bluecloth.rb +0 -19
- data/lib/nanoc3/filters/coderay.rb +0 -21
- data/lib/nanoc3/filters/colorize_syntax.rb +0 -261
- data/lib/nanoc3/filters/erb.rb +0 -35
- data/lib/nanoc3/filters/erubis.rb +0 -27
- data/lib/nanoc3/filters/haml.rb +0 -27
- data/lib/nanoc3/filters/kramdown.rb +0 -20
- data/lib/nanoc3/filters/less.rb +0 -53
- data/lib/nanoc3/filters/markaby.rb +0 -20
- data/lib/nanoc3/filters/maruku.rb +0 -20
- data/lib/nanoc3/filters/mustache.rb +0 -24
- data/lib/nanoc3/filters/rainpress.rb +0 -19
- data/lib/nanoc3/filters/rdiscount.rb +0 -22
- data/lib/nanoc3/filters/rdoc.rb +0 -33
- data/lib/nanoc3/filters/redcarpet.rb +0 -27
- data/lib/nanoc3/filters/redcloth.rb +0 -47
- data/lib/nanoc3/filters/relativize_paths.rb +0 -45
- data/lib/nanoc3/filters/rubypants.rb +0 -20
- data/lib/nanoc3/filters/sass.rb +0 -66
- data/lib/nanoc3/filters/slim.rb +0 -25
- data/lib/nanoc3/filters/typogruby.rb +0 -23
- data/lib/nanoc3/filters/uglify_js.rb +0 -42
- data/lib/nanoc3/helpers.rb +0 -16
- data/lib/nanoc3/helpers/blogging.rb +0 -319
- data/lib/nanoc3/helpers/breadcrumbs.rb +0 -40
- data/lib/nanoc3/helpers/capturing.rb +0 -138
- data/lib/nanoc3/helpers/filtering.rb +0 -50
- data/lib/nanoc3/helpers/html_escape.rb +0 -55
- data/lib/nanoc3/helpers/link_to.rb +0 -151
- data/lib/nanoc3/helpers/rendering.rb +0 -140
- data/lib/nanoc3/helpers/tagging.rb +0 -71
- data/lib/nanoc3/helpers/text.rb +0 -44
- data/lib/nanoc3/helpers/xml_sitemap.rb +0 -76
- data/lib/nanoc3/tasks.rb +0 -10
- data/lib/nanoc3/tasks/clean.rake +0 -16
- data/lib/nanoc3/tasks/clean.rb +0 -29
- data/lib/nanoc3/tasks/deploy/rsync.rake +0 -14
- data/lib/nanoc3/tasks/validate.rake +0 -92
- data/nanoc3.gemspec +0 -49
- data/tasks/doc.rake +0 -16
- data/tasks/test.rake +0 -44
- data/test/base/core_ext/array_spec.rb +0 -73
- data/test/base/core_ext/hash_spec.rb +0 -98
- data/test/base/core_ext/pathname_spec.rb +0 -27
- data/test/base/core_ext/string_spec.rb +0 -37
- data/test/base/test_checksum_store.rb +0 -35
- data/test/base/test_code_snippet.rb +0 -31
- data/test/base/test_compiler.rb +0 -316
- data/test/base/test_compiler_dsl.rb +0 -161
- data/test/base/test_context.rb +0 -31
- data/test/base/test_data_source.rb +0 -46
- data/test/base/test_dependency_tracker.rb +0 -262
- data/test/base/test_directed_graph.rb +0 -283
- data/test/base/test_filter.rb +0 -83
- data/test/base/test_item.rb +0 -179
- data/test/base/test_item_rep.rb +0 -553
- data/test/base/test_layout.rb +0 -59
- data/test/base/test_memoization.rb +0 -90
- data/test/base/test_notification_center.rb +0 -34
- data/test/base/test_outdatedness_checker.rb +0 -394
- data/test/base/test_plugin.rb +0 -30
- data/test/base/test_rule.rb +0 -19
- data/test/base/test_rule_context.rb +0 -65
- data/test/base/test_site.rb +0 -190
- data/test/cli/commands/test_compile.rb +0 -33
- data/test/cli/commands/test_create_item.rb +0 -14
- data/test/cli/commands/test_create_layout.rb +0 -28
- data/test/cli/commands/test_create_site.rb +0 -24
- data/test/cli/commands/test_help.rb +0 -12
- data/test/cli/commands/test_info.rb +0 -11
- data/test/cli/commands/test_update.rb +0 -10
- data/test/cli/test_cli.rb +0 -102
- data/test/cli/test_error_handler.rb +0 -29
- data/test/cli/test_logger.rb +0 -10
- data/test/data_sources/test_filesystem.rb +0 -433
- data/test/data_sources/test_filesystem_unified.rb +0 -536
- data/test/data_sources/test_filesystem_verbose.rb +0 -357
- data/test/extra/core_ext/test_enumerable.rb +0 -30
- data/test/extra/core_ext/test_time.rb +0 -15
- data/test/extra/deployers/test_rsync.rb +0 -232
- data/test/extra/test_auto_compiler.rb +0 -417
- data/test/extra/test_file_proxy.rb +0 -19
- data/test/extra/test_vcs.rb +0 -22
- data/test/extra/validators/test_links.rb +0 -51
- data/test/extra/validators/test_w3c.rb +0 -47
- data/test/filters/test_asciidoc.rb +0 -22
- data/test/filters/test_bluecloth.rb +0 -18
- data/test/filters/test_coderay.rb +0 -44
- data/test/filters/test_colorize_syntax.rb +0 -283
- data/test/filters/test_erb.rb +0 -99
- data/test/filters/test_erubis.rb +0 -70
- data/test/filters/test_haml.rb +0 -96
- data/test/filters/test_kramdown.rb +0 -18
- data/test/filters/test_less.rb +0 -113
- data/test/filters/test_markaby.rb +0 -24
- data/test/filters/test_maruku.rb +0 -18
- data/test/filters/test_mustache.rb +0 -25
- data/test/filters/test_rainpress.rb +0 -29
- data/test/filters/test_rdiscount.rb +0 -31
- data/test/filters/test_rdoc.rb +0 -18
- data/test/filters/test_redcarpet.rb +0 -63
- data/test/filters/test_redcloth.rb +0 -33
- data/test/filters/test_relativize_paths.rb +0 -332
- data/test/filters/test_rubypants.rb +0 -18
- data/test/filters/test_sass.rb +0 -229
- data/test/filters/test_slim.rb +0 -35
- data/test/filters/test_typogruby.rb +0 -21
- data/test/filters/test_uglify_js.rb +0 -30
- data/test/gem_loader.rb +0 -11
- data/test/helper.rb +0 -179
- data/test/helpers/test_blogging.rb +0 -754
- data/test/helpers/test_breadcrumbs.rb +0 -81
- data/test/helpers/test_capturing.rb +0 -41
- data/test/helpers/test_filtering.rb +0 -106
- data/test/helpers/test_html_escape.rb +0 -32
- data/test/helpers/test_link_to.rb +0 -249
- data/test/helpers/test_rendering.rb +0 -89
- data/test/helpers/test_tagging.rb +0 -87
- data/test/helpers/test_text.rb +0 -24
- data/test/helpers/test_xml_sitemap.rb +0 -103
- data/test/tasks/test_clean.rb +0 -67
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3::Helpers
|
|
4
|
-
|
|
5
|
-
# Provides support for breadcrumbs, which allow the user to go up in the
|
|
6
|
-
# page hierarchy.
|
|
7
|
-
module Breadcrumbs
|
|
8
|
-
|
|
9
|
-
# Creates a breadcrumb trail leading from the current item to its parent,
|
|
10
|
-
# to its parent’s parent, etc, until the root item is reached. This
|
|
11
|
-
# function does not require that each intermediate item exist; for
|
|
12
|
-
# example, if there is no `/foo/` item, breadcrumbs for a `/foo/bar/` item
|
|
13
|
-
# will contain a `nil` element.
|
|
14
|
-
#
|
|
15
|
-
# @return [Array] The breadcrumbs, starting with the root item and ending
|
|
16
|
-
# with the item itself
|
|
17
|
-
def breadcrumbs_trail
|
|
18
|
-
breadcrumbs_for_identifier(@item.identifier)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def item_with_identifier(identifier)
|
|
22
|
-
@identifier_cache ||= {}
|
|
23
|
-
@identifier_cache[identifier] ||= begin
|
|
24
|
-
@items.find { |i| i.identifier == identifier }
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def breadcrumbs_for_identifier(identifier)
|
|
29
|
-
@breadcrumbs_cache ||= {}
|
|
30
|
-
@breadcrumbs_cache[identifier] ||= begin
|
|
31
|
-
head = (identifier == '/' ? [] : breadcrumbs_for_identifier(identifier.sub(/[^\/]+\/$/, '')) )
|
|
32
|
-
tail = [ item_with_identifier(identifier) ]
|
|
33
|
-
|
|
34
|
-
head + tail
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3::Helpers
|
|
4
|
-
|
|
5
|
-
# Provides functionality for “capturing” content in one place and reusing
|
|
6
|
-
# this content elsewhere.
|
|
7
|
-
#
|
|
8
|
-
# For example, suppose you want the sidebar of your site to contain a short
|
|
9
|
-
# summary of the item. You could put the summary in the meta file, but
|
|
10
|
-
# that’s not possible when the summary contains eRuby. You could also put
|
|
11
|
-
# the sidebar inside the actual item, but that’s not very pretty. Instead,
|
|
12
|
-
# you write the summary on the item itself, but capture it, and print it in
|
|
13
|
-
# the sidebar layout.
|
|
14
|
-
#
|
|
15
|
-
# This helper has been tested with ERB and Haml. Other filters may not work
|
|
16
|
-
# correctly.
|
|
17
|
-
#
|
|
18
|
-
# @example Capturing content for a summary
|
|
19
|
-
#
|
|
20
|
-
# <% content_for :summary do %>
|
|
21
|
-
# <p>On this item, nanoc is introduced, blah blah.</p>
|
|
22
|
-
# <% end %>
|
|
23
|
-
#
|
|
24
|
-
# @example Showing captured content in a sidebar
|
|
25
|
-
#
|
|
26
|
-
# <div id="sidebar">
|
|
27
|
-
# <h3>Summary</h3>
|
|
28
|
-
# <%= content_for(@item, :summary) || '(no summary)' %>
|
|
29
|
-
# </div>
|
|
30
|
-
#
|
|
31
|
-
# @example Showing captured content in a sidebar the old, deprecated way (do not use or I will become very angry)
|
|
32
|
-
#
|
|
33
|
-
# <div id="sidebar">
|
|
34
|
-
# <h3>Summary</h3>
|
|
35
|
-
# <%= @item[:content_for_summary] || '(no summary)' %>
|
|
36
|
-
# </div>
|
|
37
|
-
module Capturing
|
|
38
|
-
|
|
39
|
-
# @api private
|
|
40
|
-
class CapturesStore
|
|
41
|
-
|
|
42
|
-
require 'singleton'
|
|
43
|
-
include Singleton
|
|
44
|
-
|
|
45
|
-
def initialize
|
|
46
|
-
@store = {}
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def []=(item, name, content)
|
|
50
|
-
@store[item.identifier] ||= {}
|
|
51
|
-
@store[item.identifier][name] = content
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def [](item, name)
|
|
55
|
-
@store[item.identifier] ||= {}
|
|
56
|
-
@store[item.identifier][name]
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# @overload content_for(name, &block)
|
|
62
|
-
#
|
|
63
|
-
# Captures the content inside the block and stores it so that it can be
|
|
64
|
-
# referenced later on. The same method, {#content_for}, is used for
|
|
65
|
-
# getting the captured content as well as setting it. When capturing,
|
|
66
|
-
# the content of the block itself will not be outputted.
|
|
67
|
-
#
|
|
68
|
-
# For backwards compatibility, it is also possible to fetch the captured
|
|
69
|
-
# content by getting the contents of the attribute named `content_for_`
|
|
70
|
-
# followed by the given name. This way of accessing captures is
|
|
71
|
-
# deprecated.
|
|
72
|
-
#
|
|
73
|
-
# @param [Symbol, String] name The base name of the attribute into which
|
|
74
|
-
# the content should be stored
|
|
75
|
-
#
|
|
76
|
-
# @return [void]
|
|
77
|
-
#
|
|
78
|
-
# @overload content_for(item, name)
|
|
79
|
-
#
|
|
80
|
-
# Fetches the capture with the given name from the given item and
|
|
81
|
-
# returns it.
|
|
82
|
-
#
|
|
83
|
-
# @param [Nanoc3::Item] item The item for which to get the capture
|
|
84
|
-
#
|
|
85
|
-
# @param [Symbol, String] name The name of the capture to fetch
|
|
86
|
-
#
|
|
87
|
-
# @return [String] The stored captured content
|
|
88
|
-
def content_for(*args, &block)
|
|
89
|
-
if block_given? # Set content
|
|
90
|
-
# Get args
|
|
91
|
-
if args.size != 1
|
|
92
|
-
raise ArgumentError, "expected 1 argument (the name " +
|
|
93
|
-
"of the capture) but got #{args.size} instead"
|
|
94
|
-
end
|
|
95
|
-
name = args[0]
|
|
96
|
-
|
|
97
|
-
# Capture and store
|
|
98
|
-
content = capture(&block)
|
|
99
|
-
CapturesStore.instance[@item, name.to_sym] = content
|
|
100
|
-
else # Get content
|
|
101
|
-
# Get args
|
|
102
|
-
if args.size != 2
|
|
103
|
-
raise ArgumentError, "expected 2 arguments (the item " +
|
|
104
|
-
"and the name of the capture) but got #{args.size} instead"
|
|
105
|
-
end
|
|
106
|
-
item = args[0]
|
|
107
|
-
name = args[1]
|
|
108
|
-
|
|
109
|
-
# Get content
|
|
110
|
-
CapturesStore.instance[item, name.to_sym]
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
# Evaluates the given block and returns its contents. The contents of the
|
|
115
|
-
# block is not outputted.
|
|
116
|
-
#
|
|
117
|
-
# @return [String] The captured result
|
|
118
|
-
def capture(&block)
|
|
119
|
-
# Get erbout so far
|
|
120
|
-
erbout = eval('_erbout', block.binding)
|
|
121
|
-
erbout_length = erbout.length
|
|
122
|
-
|
|
123
|
-
# Execute block
|
|
124
|
-
block.call
|
|
125
|
-
|
|
126
|
-
# Get new piece of erbout
|
|
127
|
-
erbout_addition = erbout[erbout_length..-1]
|
|
128
|
-
|
|
129
|
-
# Remove addition
|
|
130
|
-
erbout[erbout_length..-1] = ''
|
|
131
|
-
|
|
132
|
-
# Done
|
|
133
|
-
erbout_addition
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3::Helpers
|
|
4
|
-
|
|
5
|
-
# Provides functionality for filtering parts of an item or a layout.
|
|
6
|
-
module Filtering
|
|
7
|
-
|
|
8
|
-
require 'nanoc3/helpers/capturing'
|
|
9
|
-
include Nanoc3::Helpers::Capturing
|
|
10
|
-
|
|
11
|
-
# Filters the content in the given block and outputs it. This function
|
|
12
|
-
# does not return anything; instead, the filtered contents is directly
|
|
13
|
-
# appended to the output buffer (`_erbout`).
|
|
14
|
-
#
|
|
15
|
-
# This function has been tested with ERB and Haml. Other filters may not
|
|
16
|
-
# work correctly.
|
|
17
|
-
#
|
|
18
|
-
# @example Running a filter on a part of an item or layout
|
|
19
|
-
#
|
|
20
|
-
# <p>Lorem ipsum dolor sit amet...</p>
|
|
21
|
-
# <% filter :rubypants do %>
|
|
22
|
-
# <p>Consectetur adipisicing elit...</p>
|
|
23
|
-
# <% end %>
|
|
24
|
-
#
|
|
25
|
-
# @param [Symbol] filter_name The name of the filter to run on the
|
|
26
|
-
# contents of the block
|
|
27
|
-
#
|
|
28
|
-
# @param [Hash] argument Arguments to pass to the filter
|
|
29
|
-
#
|
|
30
|
-
# @return [void]
|
|
31
|
-
def filter(filter_name, arguments={}, &block)
|
|
32
|
-
# Capture block
|
|
33
|
-
data = capture(&block)
|
|
34
|
-
|
|
35
|
-
# Find filter
|
|
36
|
-
klass = Nanoc3::Filter.named(filter_name)
|
|
37
|
-
raise Nanoc3::Errors::UnknownFilter.new(filter_name) if klass.nil?
|
|
38
|
-
filter = klass.new(@item_rep.assigns)
|
|
39
|
-
|
|
40
|
-
# Filter captured data
|
|
41
|
-
filtered_data = filter.run(data, arguments)
|
|
42
|
-
|
|
43
|
-
# Append filtered data to buffer
|
|
44
|
-
buffer = eval('_erbout', block.binding)
|
|
45
|
-
buffer << filtered_data
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3::Helpers
|
|
4
|
-
|
|
5
|
-
# Contains functionality for HTML-escaping strings.
|
|
6
|
-
module HTMLEscape
|
|
7
|
-
|
|
8
|
-
require 'nanoc3/helpers/capturing'
|
|
9
|
-
include Nanoc3::Helpers::Capturing
|
|
10
|
-
|
|
11
|
-
# Returns the HTML-escaped representation of the given string or the given
|
|
12
|
-
# block. Only `&`, `<`, `>` and `"` are escaped. When given a block, the
|
|
13
|
-
# contents of the block will be escaped and appended to the output buffer,
|
|
14
|
-
# `_erbout`.
|
|
15
|
-
#
|
|
16
|
-
# @example Escaping a string
|
|
17
|
-
#
|
|
18
|
-
# h('<br>')
|
|
19
|
-
# # => '<br>'
|
|
20
|
-
#
|
|
21
|
-
# @example Escaping with a block
|
|
22
|
-
#
|
|
23
|
-
# <% h do %>
|
|
24
|
-
# <h1>Hello <em>world</em>!</h1>
|
|
25
|
-
# <% end %>
|
|
26
|
-
# # The buffer will now contain “<h1>Hello <em>world</em>!</h1>”
|
|
27
|
-
#
|
|
28
|
-
# @param [String] string The string to escape
|
|
29
|
-
#
|
|
30
|
-
# @return [String] The escaped string
|
|
31
|
-
def html_escape(string=nil, &block)
|
|
32
|
-
if block_given?
|
|
33
|
-
# Capture and escape block
|
|
34
|
-
data = capture(&block)
|
|
35
|
-
escaped_data = html_escape(data)
|
|
36
|
-
|
|
37
|
-
# Append filtered data to buffer
|
|
38
|
-
buffer = eval('_erbout', block.binding)
|
|
39
|
-
buffer << escaped_data
|
|
40
|
-
elsif string
|
|
41
|
-
string.gsub('&', '&').
|
|
42
|
-
gsub('<', '<').
|
|
43
|
-
gsub('>', '>').
|
|
44
|
-
gsub('"', '"')
|
|
45
|
-
else
|
|
46
|
-
raise RuntimeError, "The #html_escape or #h function needs either a " \
|
|
47
|
-
"string or a block to HTML-escape, but neither a string nor a block was given"
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
alias h html_escape
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
end
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3::Helpers
|
|
4
|
-
|
|
5
|
-
# Contains functions for linking to items and item representations.
|
|
6
|
-
module LinkTo
|
|
7
|
-
|
|
8
|
-
require 'nanoc3/helpers/html_escape'
|
|
9
|
-
include Nanoc3::Helpers::HTMLEscape
|
|
10
|
-
|
|
11
|
-
# Creates a HTML link to the given path or item representation, and with
|
|
12
|
-
# the given text. All attributes of the `a` element, including the `href`
|
|
13
|
-
# attribute, will be HTML-escaped; the contents of the `a` element, which
|
|
14
|
-
# can contain markup, will not be HTML-escaped. The HTML-escaping is done
|
|
15
|
-
# using {Nanoc3::Helpers::HTMLEscape#html_escape}.
|
|
16
|
-
#
|
|
17
|
-
# @param [String] text The visible link text
|
|
18
|
-
#
|
|
19
|
-
# @param [String, Nanoc3::Item, Nanoc3::ItemRep] target The path/URL,
|
|
20
|
-
# item or item representation that should be linked to
|
|
21
|
-
#
|
|
22
|
-
# @param [Hash] attributes A hash containing HTML attributes (e.g.
|
|
23
|
-
# `rel`, `title`, …) that will be added to the link.
|
|
24
|
-
#
|
|
25
|
-
# @return [String] The link text
|
|
26
|
-
#
|
|
27
|
-
# @example Linking to a path
|
|
28
|
-
#
|
|
29
|
-
# link_to('Blog', '/blog/')
|
|
30
|
-
# # => '<a href="/blog/">Blog</a>'
|
|
31
|
-
#
|
|
32
|
-
# @example Linking to an item
|
|
33
|
-
#
|
|
34
|
-
# about = @items.find { |i| i.identifier == '/about/' }
|
|
35
|
-
# link_to('About Me', about)
|
|
36
|
-
# # => '<a href="/about.html">About Me</a>'
|
|
37
|
-
#
|
|
38
|
-
# @example Linking to an item representation
|
|
39
|
-
#
|
|
40
|
-
# about = @items.find { |i| i.identifier == '/about/' }
|
|
41
|
-
# link_to('My vCard', about.rep(:vcard))
|
|
42
|
-
# # => '<a href="/about.vcf">My vCard</a>'
|
|
43
|
-
#
|
|
44
|
-
# @example Linking with custom attributes
|
|
45
|
-
#
|
|
46
|
-
# link_to('Blog', '/blog/', :title => 'My super cool blog')
|
|
47
|
-
# # => '<a title="My super cool blog" href="/blog/">Blog</a>'
|
|
48
|
-
def link_to(text, target, attributes={})
|
|
49
|
-
# Find path
|
|
50
|
-
if target.is_a?(String)
|
|
51
|
-
path = target
|
|
52
|
-
else
|
|
53
|
-
path = target.path
|
|
54
|
-
raise RuntimeError, "Cannot create a link to #{target.inspect} because this target is not outputted (its routing rule returns nil)" if path.nil?
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# Join attributes
|
|
58
|
-
attributes = attributes.inject('') do |memo, (key, value)|
|
|
59
|
-
memo + key.to_s + '="' + h(value) + '" '
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# Create link
|
|
63
|
-
"<a #{attributes}href=\"#{h path}\">#{text}</a>"
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Creates a HTML link using {#link_to}, except when the linked item is
|
|
67
|
-
# the current one. In this case, a span element with class “active” and
|
|
68
|
-
# with the given text will be returned. The HTML-escaping rules for
|
|
69
|
-
# {#link_to} apply here as well.
|
|
70
|
-
#
|
|
71
|
-
# @param [String] text The visible link text
|
|
72
|
-
#
|
|
73
|
-
# @param [String, Nanoc3::Item, Nanoc3::ItemRep] target The path/URL,
|
|
74
|
-
# item or item representation that should be linked to
|
|
75
|
-
#
|
|
76
|
-
# @param [Hash] attributes A hash containing HTML attributes (e.g.
|
|
77
|
-
# `rel`, `title`, …) that will be added to the link.
|
|
78
|
-
#
|
|
79
|
-
# @return [String] The link text
|
|
80
|
-
#
|
|
81
|
-
# @example Linking to a different page
|
|
82
|
-
#
|
|
83
|
-
# link_to_unless_current('Blog', '/blog/')
|
|
84
|
-
# # => '<a href="/blog/">Blog</a>'
|
|
85
|
-
#
|
|
86
|
-
# @example Linking to the same page
|
|
87
|
-
#
|
|
88
|
-
# link_to_unless_current('This Item', @item)
|
|
89
|
-
# # => '<span class="active" title="You\'re here.">This Item</span>'
|
|
90
|
-
def link_to_unless_current(text, target, attributes={})
|
|
91
|
-
# Find path
|
|
92
|
-
path = target.is_a?(String) ? target : target.path
|
|
93
|
-
|
|
94
|
-
if @item_rep && @item_rep.path == path
|
|
95
|
-
# Create message
|
|
96
|
-
"<span class=\"active\" title=\"You're here.\">#{text}</span>"
|
|
97
|
-
else
|
|
98
|
-
link_to(text, target, attributes)
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# Returns the relative path from the current item to the given path or
|
|
103
|
-
# item representation. The returned path will not be HTML-escaped.
|
|
104
|
-
#
|
|
105
|
-
# @param [String, Nanoc3::Item, Nanoc3::ItemRep] target The path/URL,
|
|
106
|
-
# item or item representation to which the relative path should be
|
|
107
|
-
# generated
|
|
108
|
-
#
|
|
109
|
-
# @return [String] The relative path to the target
|
|
110
|
-
#
|
|
111
|
-
# @example
|
|
112
|
-
#
|
|
113
|
-
# # if the current item's path is /foo/bar/
|
|
114
|
-
# relative_path_to('/foo/qux/')
|
|
115
|
-
# # => '../qux/'
|
|
116
|
-
def relative_path_to(target)
|
|
117
|
-
require 'pathname'
|
|
118
|
-
|
|
119
|
-
# Find path
|
|
120
|
-
if target.is_a?(String)
|
|
121
|
-
path = target
|
|
122
|
-
else
|
|
123
|
-
path = target.path
|
|
124
|
-
raise RuntimeError, "Cannot get the relative path to #{target.inspect} because this target is not outputted (its routing rule returns nil)" if path.nil?
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
# Get source and destination paths
|
|
128
|
-
dst_path = Pathname.new(path)
|
|
129
|
-
raise RuntimeError, "Cannot get the relative path to #{path} because the current item representation, #{@item_rep.inspect}, is not outputted (its routing rule returns nil)" if @item_rep.path.nil?
|
|
130
|
-
src_path = Pathname.new(@item_rep.path)
|
|
131
|
-
|
|
132
|
-
# Calculate the relative path (method depends on whether destination is
|
|
133
|
-
# a directory or not).
|
|
134
|
-
if src_path.to_s[-1,1] != '/'
|
|
135
|
-
relative_path = dst_path.relative_path_from(src_path.dirname).to_s
|
|
136
|
-
else
|
|
137
|
-
relative_path = dst_path.relative_path_from(src_path).to_s
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
# Add trailing slash if necessary
|
|
141
|
-
if dst_path.to_s[-1,1] == '/'
|
|
142
|
-
relative_path << '/'
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
# Done
|
|
146
|
-
relative_path
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
end
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3::Helpers
|
|
4
|
-
|
|
5
|
-
# Provides functionality for rendering layouts as partials.
|
|
6
|
-
module Rendering
|
|
7
|
-
|
|
8
|
-
include Nanoc3::Helpers::Capturing
|
|
9
|
-
|
|
10
|
-
# Renders the given layout. The given layout will be run through the first
|
|
11
|
-
# matching layout rule.
|
|
12
|
-
#
|
|
13
|
-
# When this method is invoked _without_ a block, the return value will be
|
|
14
|
-
# the rendered layout (a string) and `_erbout` will not be modified.
|
|
15
|
-
#
|
|
16
|
-
# When this method is invoked _with_ a block, an empty string will be
|
|
17
|
-
# returned and the rendered content will be appended to `_erbout`. In this
|
|
18
|
-
# case, the content of the block will be captured (using the
|
|
19
|
-
# {Nanoc3::Helpers::Capturing} helper) and this content will be made
|
|
20
|
-
# available with `yield`. In other words, a `yield` inside the partial
|
|
21
|
-
# will output the content of the block passed to the method.
|
|
22
|
-
#
|
|
23
|
-
# (For the curious: the reason why {#render} with a block has this
|
|
24
|
-
# behaviour of returning an empty string and modifying `_erbout` is
|
|
25
|
-
# because ERB does not support combining the `<%= ... %>` form with a
|
|
26
|
-
# method call that takes a block.)
|
|
27
|
-
#
|
|
28
|
-
# The assigns (`@item`, `@config`, …) will be available in the partial. It
|
|
29
|
-
# is also possible to pass custom assigns to the method; these assigns
|
|
30
|
-
# will be made available as instance variables inside the partial.
|
|
31
|
-
#
|
|
32
|
-
# @param [String] identifier The identifier of the layout that should be
|
|
33
|
-
# rendered
|
|
34
|
-
#
|
|
35
|
-
# @param [Hash] other_assigns A hash containing extra assigns that will be
|
|
36
|
-
# made available as instance variables in the partial
|
|
37
|
-
#
|
|
38
|
-
# @example Rendering a head and a foot partial around some text
|
|
39
|
-
#
|
|
40
|
-
# <%= render 'head' %> - MIDDLE - <%= render 'foot' %>
|
|
41
|
-
# # => "HEAD - MIDDLE - FOOT"
|
|
42
|
-
#
|
|
43
|
-
# @example Rendering a head partial with a custom title
|
|
44
|
-
#
|
|
45
|
-
# # The 'head' layout
|
|
46
|
-
# <h1><%= @title %></h1>
|
|
47
|
-
#
|
|
48
|
-
# # The item/layout where the partial is rendered
|
|
49
|
-
# <%= render 'head', :title => 'Foo' %>
|
|
50
|
-
# # => "<h1>Foo</h1>"
|
|
51
|
-
#
|
|
52
|
-
# @example Yielding inside a partial
|
|
53
|
-
#
|
|
54
|
-
# # The 'box' partial
|
|
55
|
-
# <div class="box">
|
|
56
|
-
# <%= yield %>
|
|
57
|
-
# </div>
|
|
58
|
-
#
|
|
59
|
-
# # The item/layout where the partial is rendered
|
|
60
|
-
# <% render 'box' do %>
|
|
61
|
-
# I'm boxy! Luvz!
|
|
62
|
-
# <% end %>
|
|
63
|
-
#
|
|
64
|
-
# # Result
|
|
65
|
-
# <div class="box">
|
|
66
|
-
# I'm boxy! Luvz!
|
|
67
|
-
# </div>
|
|
68
|
-
#
|
|
69
|
-
# @raise [Nanoc3::Errors::UnknownLayout] if the given layout does not
|
|
70
|
-
# exist
|
|
71
|
-
#
|
|
72
|
-
# @raise [Nanoc3::Errors::CannotDetermineFilter] if there is no layout
|
|
73
|
-
# rule for the given layout
|
|
74
|
-
#
|
|
75
|
-
# @raise [Nanoc3::Errors::UnknownFilter] if the layout rule for the given
|
|
76
|
-
# layout specifies an unknown filter
|
|
77
|
-
#
|
|
78
|
-
# @return [String, nil] The rendered partial, or nil if this method was
|
|
79
|
-
# invoked with a block
|
|
80
|
-
def render(identifier, other_assigns={}, &block)
|
|
81
|
-
# Find layout
|
|
82
|
-
layout = @site.layouts.find { |l| l.identifier == identifier.cleaned_identifier }
|
|
83
|
-
raise Nanoc3::Errors::UnknownLayout.new(identifier.cleaned_identifier) if layout.nil?
|
|
84
|
-
|
|
85
|
-
# Visit
|
|
86
|
-
Nanoc3::NotificationCenter.post(:visit_started, layout)
|
|
87
|
-
Nanoc3::NotificationCenter.post(:visit_ended, layout)
|
|
88
|
-
|
|
89
|
-
# Capture content, if any
|
|
90
|
-
captured_content = block_given? ? capture(&block) : nil
|
|
91
|
-
|
|
92
|
-
# Get assigns
|
|
93
|
-
assigns = {
|
|
94
|
-
:content => captured_content,
|
|
95
|
-
:item => @item,
|
|
96
|
-
:item_rep => @item_rep,
|
|
97
|
-
:items => @items,
|
|
98
|
-
:layout => layout,
|
|
99
|
-
:layouts => @layouts,
|
|
100
|
-
:config => @config,
|
|
101
|
-
:site => @site
|
|
102
|
-
}.merge(other_assigns)
|
|
103
|
-
|
|
104
|
-
# Get filter name
|
|
105
|
-
filter_name, filter_args = @site.compiler.rules_collection.filter_for_layout(layout)
|
|
106
|
-
raise Nanoc3::Errors::CannotDetermineFilter.new(layout.identifier) if filter_name.nil?
|
|
107
|
-
|
|
108
|
-
# Get filter class
|
|
109
|
-
filter_class = Nanoc3::Filter.named(filter_name)
|
|
110
|
-
raise Nanoc3::Errors::UnknownFilter.new(filter_name) if filter_class.nil?
|
|
111
|
-
|
|
112
|
-
# Create filter
|
|
113
|
-
filter = filter_class.new(assigns)
|
|
114
|
-
|
|
115
|
-
begin
|
|
116
|
-
# Notify start
|
|
117
|
-
Nanoc3::NotificationCenter.post(:processing_started, layout)
|
|
118
|
-
|
|
119
|
-
# Layout
|
|
120
|
-
result = filter.run(layout.raw_content, filter_args)
|
|
121
|
-
|
|
122
|
-
# Append to erbout if we have a block
|
|
123
|
-
if block_given?
|
|
124
|
-
# Append result and return nothing
|
|
125
|
-
erbout = eval('_erbout', block.binding)
|
|
126
|
-
erbout << result
|
|
127
|
-
''
|
|
128
|
-
else
|
|
129
|
-
# Return result
|
|
130
|
-
result
|
|
131
|
-
end
|
|
132
|
-
ensure
|
|
133
|
-
# Notify end
|
|
134
|
-
Nanoc3::NotificationCenter.post(:processing_ended, layout)
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
end
|