nanoc3 3.1.4 → 3.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.md +9 -0
- data/README.md +1 -0
- data/lib/nanoc3/base/site.rb +8 -0
- data/lib/nanoc3/cli/base.rb +35 -10
- data/lib/nanoc3/cli/logger.rb +19 -13
- data/lib/nanoc3/data_sources/filesystem.rb +1 -1
- data/lib/nanoc3/helpers/blogging.rb +19 -12
- data/lib/nanoc3/helpers/rendering.rb +27 -4
- data/lib/nanoc3.rb +1 -1
- metadata +4 -5
- data/Gemfile +0 -31
data/NEWS.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# nanoc news
|
2
2
|
|
3
|
+
## 3.1.5 (2010-08-24)
|
4
|
+
|
5
|
+
* Improved `#render` documentation
|
6
|
+
* Improved metadata section check so that e.g. raw diffs are handled properly
|
7
|
+
* Deprecated using `Nanoc3::Site#initialize` with a non-`"."` argument
|
8
|
+
* Added Ruby engine to version string
|
9
|
+
* Allowed the `created_at` and `updated_at` attributes used in the `Blogging`
|
10
|
+
helper to be `Date` instances
|
11
|
+
|
3
12
|
## 3.1.4 (2010-07-25)
|
4
13
|
|
5
14
|
* Made INT and TERM signals always quit the CLI
|
data/README.md
CHANGED
data/lib/nanoc3/base/site.rb
CHANGED
@@ -344,6 +344,9 @@ module Nanoc3
|
|
344
344
|
# Get basic path by applying matching rule
|
345
345
|
basic_path = rule.apply_to(rep)
|
346
346
|
next if basic_path.nil?
|
347
|
+
if basic_path !~ %r{^/}
|
348
|
+
raise RuntimeError, "The path returned for the #{rep.inspect} item representation, “#{basic_path}”, does not start with a slash. Please ensure that all routing rules return a path that starts with a slash.".make_compatible_with_env
|
349
|
+
end
|
347
350
|
|
348
351
|
# Get raw path by prepending output directory
|
349
352
|
rep.raw_path = self.config[:output_dir] + basic_path
|
@@ -364,6 +367,11 @@ module Nanoc3
|
|
364
367
|
# #initialize for details.
|
365
368
|
def build_config(dir_or_config_hash)
|
366
369
|
if dir_or_config_hash.is_a? String
|
370
|
+
# Check whether it is supported
|
371
|
+
if dir_or_config_hash != '.'
|
372
|
+
warn 'WARNING: Calling Nanoc3::Site.new with a directory that is not the current working directory is not supported. It is recommended to change the directory before calling Nanoc3::Site.new. For example, instead of Nanoc3::Site.new(\'abc\'), use Dir.chdir(\'abc\') { Nanoc3::Site.new(\'.\') }.'
|
373
|
+
end
|
374
|
+
|
367
375
|
# Read config from config.yaml in given dir
|
368
376
|
config_path = File.join(dir_or_config_hash, 'config.yaml')
|
369
377
|
@config = DEFAULT_CONFIG.merge(YAML.load_file(config_path).symbolize_keys)
|
data/lib/nanoc3/cli/base.rb
CHANGED
@@ -23,12 +23,20 @@ module Nanoc3::CLI
|
|
23
23
|
add_command(Nanoc3::CLI::Commands::View.new)
|
24
24
|
end
|
25
25
|
|
26
|
+
# Returns a fully initialised base instance. It is recommended to use this
|
27
|
+
# shared instance than to create new ones, as this will be the instance
|
28
|
+
# that will be used when reading all code from the `lib/` directory.
|
29
|
+
#
|
30
|
+
# @return [Nanoc3::CLI::Base]
|
26
31
|
def self.shared_base
|
27
32
|
@shared_base ||= Nanoc3::CLI::Base.new
|
28
33
|
end
|
29
34
|
|
30
|
-
#
|
31
|
-
#
|
35
|
+
# Asserts that the current working directory contains a site
|
36
|
+
# ({Nanoc3::Site} instance). If no site is present, prints an error
|
37
|
+
# message and exits.
|
38
|
+
#
|
39
|
+
# @return [void]
|
32
40
|
def require_site
|
33
41
|
if site.nil?
|
34
42
|
$stderr.puts 'The current working directory does not seem to be a ' +
|
@@ -37,7 +45,10 @@ module Nanoc3::CLI
|
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
40
|
-
# Gets the site (Nanoc3::Site) in the current directory and
|
48
|
+
# Gets the site ({Nanoc3::Site} instance) in the current directory and
|
49
|
+
# loads its data.
|
50
|
+
#
|
51
|
+
# @return [Nanoc3::Site] The site in the current working directory
|
41
52
|
def site
|
42
53
|
# Load site if possible
|
43
54
|
if File.file?('config.yaml') && (!self.instance_variable_defined?(:@site) || @site.nil?)
|
@@ -52,7 +63,7 @@ module Nanoc3::CLI
|
|
52
63
|
@site
|
53
64
|
end
|
54
65
|
|
55
|
-
#
|
66
|
+
# @see ::Cri::Base#run
|
56
67
|
def run(args)
|
57
68
|
# Set exit handler
|
58
69
|
[ 'INT', 'TERM' ].each do |signal|
|
@@ -70,8 +81,12 @@ module Nanoc3::CLI
|
|
70
81
|
exit(1)
|
71
82
|
end
|
72
83
|
|
73
|
-
# Prints the given error to stderr. Includes message, possible resolution
|
74
|
-
# compilation stack, backtrace, etc.
|
84
|
+
# Prints the given error to stderr. Includes message, possible resolution
|
85
|
+
# (see {#resolution_for}), compilation stack, backtrace, etc.
|
86
|
+
#
|
87
|
+
# @param [Error] error The error that should be described
|
88
|
+
#
|
89
|
+
# @return [void]
|
75
90
|
def print_error(error)
|
76
91
|
$stderr.puts
|
77
92
|
|
@@ -115,8 +130,12 @@ module Nanoc3::CLI
|
|
115
130
|
$stderr.puts error.backtrace.to_enum(:each_with_index).map { |item, index| " #{index}. #{item}" }.join("\n")
|
116
131
|
end
|
117
132
|
|
118
|
-
#
|
119
|
-
#
|
133
|
+
# Attempts to find a resolution for the given error, or nil if no
|
134
|
+
# resolution can be automatically obtained.
|
135
|
+
#
|
136
|
+
# @param [Error] error The error to find a resolution for
|
137
|
+
#
|
138
|
+
# @return [String] The resolution for the given error
|
120
139
|
def resolution_for(error)
|
121
140
|
# FIXME this should probably go somewhere else so that 3rd-party code can add other gem names too
|
122
141
|
gem_names = {
|
@@ -158,6 +177,10 @@ module Nanoc3::CLI
|
|
158
177
|
# Sets the data source's VCS to the VCS with the given name. Does nothing
|
159
178
|
# when the site's data source does not support VCSes (i.e. does not
|
160
179
|
# implement #vcs=).
|
180
|
+
#
|
181
|
+
# @param [String] vcs_name The name of the VCS that should be used
|
182
|
+
#
|
183
|
+
# @return [void]
|
161
184
|
def set_vcs(vcs_name)
|
162
185
|
# Skip if not possible
|
163
186
|
return if vcs_name.nil? || site.nil?
|
@@ -178,7 +201,7 @@ module Nanoc3::CLI
|
|
178
201
|
end
|
179
202
|
end
|
180
203
|
|
181
|
-
#
|
204
|
+
# @return [Array] The list of global option definitions
|
182
205
|
def global_option_definitions
|
183
206
|
[
|
184
207
|
{
|
@@ -208,13 +231,15 @@ module Nanoc3::CLI
|
|
208
231
|
]
|
209
232
|
end
|
210
233
|
|
234
|
+
# @see Cri::Base#handle_option
|
211
235
|
def handle_option(option)
|
212
236
|
case option
|
213
237
|
when :version
|
214
238
|
gem_info = defined?(Gem) ? "with RubyGems #{Gem::VERSION}" : "without RubyGems"
|
239
|
+
engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
|
215
240
|
|
216
241
|
puts "nanoc #{Nanoc3::VERSION} (c) 2007-2010 Denis Defreyne."
|
217
|
-
puts "
|
242
|
+
puts "Running #{engine} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) on #{RUBY_PLATFORM} #{gem_info}"
|
218
243
|
exit 0
|
219
244
|
when :verbose
|
220
245
|
Nanoc3::CLI::Logger.instance.level = :low
|
data/lib/nanoc3/cli/logger.rb
CHANGED
@@ -8,6 +8,8 @@ module Nanoc3::CLI
|
|
8
8
|
# feedback in the terminal.
|
9
9
|
class Logger
|
10
10
|
|
11
|
+
# Maps actions (`:create`, `:update`, `:identical` and `:skip`) onto their
|
12
|
+
# ANSI color codes.
|
11
13
|
ACTION_COLORS = {
|
12
14
|
:create => "\e[1m" + "\e[32m", # bold + green
|
13
15
|
:update => "\e[1m" + "\e[33m", # bold + yellow
|
@@ -17,12 +19,14 @@ module Nanoc3::CLI
|
|
17
19
|
|
18
20
|
include Singleton
|
19
21
|
|
20
|
-
#
|
21
|
-
# messages, only high-priority messages, or no messages at all,
|
22
|
+
# Returns the log level, which can be :high, :low or :off (which will log
|
23
|
+
# all messages, only high-priority messages, or no messages at all,
|
22
24
|
# respectively).
|
25
|
+
#
|
26
|
+
# @return [Symbol] The log level
|
23
27
|
attr_accessor :level
|
24
28
|
|
25
|
-
#
|
29
|
+
# @return [Boolean] True if color should be used, false otherwise
|
26
30
|
attr_accessor :color
|
27
31
|
alias_method :color?, :color
|
28
32
|
|
@@ -40,12 +44,13 @@ module Nanoc3::CLI
|
|
40
44
|
|
41
45
|
# Logs a file-related action.
|
42
46
|
#
|
43
|
-
#
|
47
|
+
# @param [:high, :low] level The importance of this action
|
48
|
+
#
|
49
|
+
# @param [:create, :update, :identical] action The kind of file action
|
44
50
|
#
|
45
|
-
#
|
46
|
-
# :identical.
|
51
|
+
# @param [String] name The name of the file the action was performed on
|
47
52
|
#
|
48
|
-
#
|
53
|
+
# @return [void]
|
49
54
|
def file(level, action, identifier, duration=nil)
|
50
55
|
log(
|
51
56
|
level,
|
@@ -61,18 +66,19 @@ module Nanoc3::CLI
|
|
61
66
|
|
62
67
|
# Logs a message.
|
63
68
|
#
|
64
|
-
#
|
69
|
+
# @param [:high, :low] level The importance of this message
|
70
|
+
#
|
71
|
+
# @param [String] message The message to be logged
|
65
72
|
#
|
66
|
-
#
|
73
|
+
# @param [#puts] io The stream to which the message should be written
|
67
74
|
#
|
68
|
-
#
|
69
|
-
|
70
|
-
def log(level, s, io=$stdout)
|
75
|
+
# @return [void]
|
76
|
+
def log(level, message, io=$stdout)
|
71
77
|
# Don't log when logging is disabled
|
72
78
|
return if @level == :off
|
73
79
|
|
74
80
|
# Log when level permits it
|
75
|
-
io.puts(
|
81
|
+
io.puts(message) if (@level == :low or @level == level)
|
76
82
|
end
|
77
83
|
|
78
84
|
end
|
@@ -39,8 +39,7 @@ module Nanoc3::Helpers
|
|
39
39
|
def sorted_articles
|
40
40
|
require 'time'
|
41
41
|
articles.sort_by do |a|
|
42
|
-
|
43
|
-
time.is_a?(String) ? Time.parse(time) : time
|
42
|
+
attribute_to_time(a[:created_at])
|
44
43
|
end.reverse
|
45
44
|
end
|
46
45
|
|
@@ -183,8 +182,7 @@ module Nanoc3::Helpers
|
|
183
182
|
|
184
183
|
# Get sorted relevant articles
|
185
184
|
sorted_relevant_articles = relevant_articles.sort_by do |a|
|
186
|
-
|
187
|
-
time.is_a?(String) ? Time.parse(time) : time
|
185
|
+
attribute_to_time(a[:created_at])
|
188
186
|
end.reverse.first(limit)
|
189
187
|
|
190
188
|
# Get most recent article
|
@@ -204,8 +202,7 @@ module Nanoc3::Helpers
|
|
204
202
|
xml.title title
|
205
203
|
|
206
204
|
# Add date
|
207
|
-
|
208
|
-
xml.updated((time.is_a?(String) ? Time.parse(time) : time).to_iso8601_time)
|
205
|
+
xml.updated(attribute_to_time(last_article[:created_at]).to_iso8601_time)
|
209
206
|
|
210
207
|
# Add links
|
211
208
|
xml.link(:rel => 'alternate', :href => root_url)
|
@@ -229,10 +226,8 @@ module Nanoc3::Helpers
|
|
229
226
|
xml.title a[:title], :type => 'html'
|
230
227
|
|
231
228
|
# Add dates
|
232
|
-
|
233
|
-
|
234
|
-
xml.published((create_time.is_a?(String) ? Time.parse(create_time) : create_time).to_iso8601_time)
|
235
|
-
xml.updated( (update_time.is_a?(String) ? Time.parse(update_time) : update_time).to_iso8601_time)
|
229
|
+
xml.published attribute_to_time(a[:created_at]).to_iso8601_time
|
230
|
+
xml.updated attribute_to_time(a[:updated_at] || a[:created_at]).to_iso8601_time
|
236
231
|
|
237
232
|
# Add link
|
238
233
|
xml.link(:rel => 'alternate', :href => url)
|
@@ -297,12 +292,24 @@ module Nanoc3::Helpers
|
|
297
292
|
|
298
293
|
hostname, base_dir = %r{^.+?://([^/]+)(.*)$}.match(@site.config[:base_url])[1..2]
|
299
294
|
|
300
|
-
|
301
|
-
formatted_date = (time.is_a?(String) ? Time.parse(time) : time).to_iso8601_date
|
295
|
+
formatted_date = attribute_to_time(item[:created_at]).to_iso8601_date
|
302
296
|
|
303
297
|
'tag:' + hostname + ',' + formatted_date + ':' + base_dir + (item.path || item.identifier)
|
304
298
|
end
|
305
299
|
|
300
|
+
# Converts the given attribute (which can be a string, a Time or a Date)
|
301
|
+
# into a Time.
|
302
|
+
#
|
303
|
+
# @param [String, Time, Date] time Something that contains time
|
304
|
+
# information but is not necessarily a Time instance yet
|
305
|
+
#
|
306
|
+
# @return [Time] The Time instance corresponding to the given input
|
307
|
+
def attribute_to_time(time)
|
308
|
+
time = Time.local(time.year, time.month, time.day) if time.is_a?(Date)
|
309
|
+
time = Time.parse(time) if time.is_a?(String)
|
310
|
+
time
|
311
|
+
end
|
312
|
+
|
306
313
|
end
|
307
314
|
|
308
315
|
end
|
@@ -7,13 +7,24 @@ module Nanoc3::Helpers
|
|
7
7
|
|
8
8
|
include Nanoc3::Helpers::Capturing
|
9
9
|
|
10
|
-
# Returns a string containing the rendered given layout.
|
10
|
+
# Returns a string containing the rendered given layout. The given layout
|
11
|
+
# will first be run through the matching layout rule.
|
12
|
+
#
|
13
|
+
# The assigns (`@item`, `@config`, …) will not be available in the
|
14
|
+
# partial, but it is possible to pass custom assigns to the method. These
|
15
|
+
# assigns will be made available as instance variables inside the partial.
|
16
|
+
#
|
17
|
+
# The method can also take a block. In this case, the content of the block
|
18
|
+
# will be captured (using the {Nanoc3::Helpers::Capturing} helper) and
|
19
|
+
# this content will be made available with `yield`. In other words, a
|
20
|
+
# `yield` inside the partial will output the content of the block passed
|
21
|
+
# to the method.
|
11
22
|
#
|
12
23
|
# @param [String] identifier The identifier of the layout that should be
|
13
|
-
#
|
24
|
+
# rendered
|
14
25
|
#
|
15
26
|
# @param [Hash] other_assigns A hash containing assigns that will be made
|
16
|
-
#
|
27
|
+
# available as instance variables in the partial
|
17
28
|
#
|
18
29
|
# @example Rendering a head and a foot partial around some text
|
19
30
|
#
|
@@ -29,8 +40,20 @@ module Nanoc3::Helpers
|
|
29
40
|
# <%= render 'head', :title => 'Foo' %>
|
30
41
|
# # => "<h1>Foo</h1>"
|
31
42
|
#
|
43
|
+
# @example Yielding inside a partial
|
44
|
+
#
|
45
|
+
# # The 'box' partial
|
46
|
+
# <div class="box">
|
47
|
+
# <%= yield %>
|
48
|
+
# </div>
|
49
|
+
#
|
50
|
+
# # The item/layout where the partial is rendered
|
51
|
+
# <% render 'box' do %>
|
52
|
+
# I'm boxy! Luvz!
|
53
|
+
# <% end %>
|
54
|
+
#
|
32
55
|
# @raise [Nanoc3::Errors::UnknownLayout] if the given layout does not
|
33
|
-
#
|
56
|
+
# exist
|
34
57
|
#
|
35
58
|
# @return [String] The rendered partial
|
36
59
|
def render(identifier, other_assigns={}, &block)
|
data/lib/nanoc3.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nanoc3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 3.1.
|
9
|
+
- 5
|
10
|
+
version: 3.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Denis Defreyne
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-24 00:00:00 +02:00
|
19
19
|
default_executable: nanoc3
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -47,7 +47,6 @@ extra_rdoc_files:
|
|
47
47
|
- NEWS.md
|
48
48
|
files:
|
49
49
|
- ChangeLog
|
50
|
-
- Gemfile
|
51
50
|
- LICENSE
|
52
51
|
- NEWS.md
|
53
52
|
- Rakefile
|
data/Gemfile
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
gem "cri"
|
4
|
-
|
5
|
-
group :development do
|
6
|
-
gem "minitest"
|
7
|
-
gem "mocha"
|
8
|
-
gem "yard"
|
9
|
-
end
|
10
|
-
|
11
|
-
group :extra do
|
12
|
-
gem "adsf"
|
13
|
-
gem "bluecloth"
|
14
|
-
gem "builder"
|
15
|
-
gem "coderay"
|
16
|
-
gem "erubis"
|
17
|
-
gem "haml"
|
18
|
-
gem "kramdown"
|
19
|
-
gem "less"
|
20
|
-
gem "markaby"
|
21
|
-
gem "maruku"
|
22
|
-
gem "mime-types"
|
23
|
-
gem "nokogiri"
|
24
|
-
gem "rack"
|
25
|
-
gem "rainpress"
|
26
|
-
gem "rdiscount"
|
27
|
-
gem "rdoc"
|
28
|
-
gem "RedCloth"
|
29
|
-
gem "rubypants"
|
30
|
-
gem "w3c_validators"
|
31
|
-
end
|