nanoc2 2.2.3
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.
- data/ChangeLog +3 -0
- data/LICENSE +19 -0
- data/README +75 -0
- data/Rakefile +76 -0
- data/bin/nanoc2 +26 -0
- data/lib/nanoc2.rb +73 -0
- data/lib/nanoc2/base.rb +26 -0
- data/lib/nanoc2/base/asset.rb +117 -0
- data/lib/nanoc2/base/asset_defaults.rb +21 -0
- data/lib/nanoc2/base/asset_rep.rb +282 -0
- data/lib/nanoc2/base/binary_filter.rb +44 -0
- data/lib/nanoc2/base/code.rb +41 -0
- data/lib/nanoc2/base/compiler.rb +67 -0
- data/lib/nanoc2/base/core_ext.rb +2 -0
- data/lib/nanoc2/base/core_ext/hash.rb +78 -0
- data/lib/nanoc2/base/core_ext/string.rb +8 -0
- data/lib/nanoc2/base/data_source.rb +286 -0
- data/lib/nanoc2/base/defaults.rb +30 -0
- data/lib/nanoc2/base/filter.rb +93 -0
- data/lib/nanoc2/base/layout.rb +91 -0
- data/lib/nanoc2/base/notification_center.rb +66 -0
- data/lib/nanoc2/base/page.rb +132 -0
- data/lib/nanoc2/base/page_defaults.rb +20 -0
- data/lib/nanoc2/base/page_rep.rb +324 -0
- data/lib/nanoc2/base/plugin.rb +71 -0
- data/lib/nanoc2/base/proxies.rb +5 -0
- data/lib/nanoc2/base/proxies/asset_proxy.rb +29 -0
- data/lib/nanoc2/base/proxies/asset_rep_proxy.rb +26 -0
- data/lib/nanoc2/base/proxies/layout_proxy.rb +25 -0
- data/lib/nanoc2/base/proxies/page_proxy.rb +35 -0
- data/lib/nanoc2/base/proxies/page_rep_proxy.rb +28 -0
- data/lib/nanoc2/base/proxy.rb +37 -0
- data/lib/nanoc2/base/router.rb +72 -0
- data/lib/nanoc2/base/site.rb +274 -0
- data/lib/nanoc2/base/template.rb +64 -0
- data/lib/nanoc2/binary_filters.rb +1 -0
- data/lib/nanoc2/binary_filters/image_science_thumbnail.rb +28 -0
- data/lib/nanoc2/cli.rb +9 -0
- data/lib/nanoc2/cli/base.rb +132 -0
- data/lib/nanoc2/cli/commands.rb +10 -0
- data/lib/nanoc2/cli/commands/autocompile.rb +80 -0
- data/lib/nanoc2/cli/commands/compile.rb +312 -0
- data/lib/nanoc2/cli/commands/create_layout.rb +85 -0
- data/lib/nanoc2/cli/commands/create_page.rb +85 -0
- data/lib/nanoc2/cli/commands/create_site.rb +323 -0
- data/lib/nanoc2/cli/commands/create_template.rb +76 -0
- data/lib/nanoc2/cli/commands/help.rb +69 -0
- data/lib/nanoc2/cli/commands/info.rb +125 -0
- data/lib/nanoc2/cli/commands/switch.rb +141 -0
- data/lib/nanoc2/cli/commands/update.rb +91 -0
- data/lib/nanoc2/cli/logger.rb +72 -0
- data/lib/nanoc2/data_sources.rb +2 -0
- data/lib/nanoc2/data_sources/filesystem.rb +707 -0
- data/lib/nanoc2/data_sources/filesystem_combined.rb +495 -0
- data/lib/nanoc2/extra.rb +6 -0
- data/lib/nanoc2/extra/auto_compiler.rb +285 -0
- data/lib/nanoc2/extra/context.rb +22 -0
- data/lib/nanoc2/extra/core_ext.rb +2 -0
- data/lib/nanoc2/extra/core_ext/hash.rb +54 -0
- data/lib/nanoc2/extra/core_ext/time.rb +13 -0
- data/lib/nanoc2/extra/file_proxy.rb +29 -0
- data/lib/nanoc2/extra/vcs.rb +48 -0
- data/lib/nanoc2/extra/vcses.rb +5 -0
- data/lib/nanoc2/extra/vcses/bazaar.rb +21 -0
- data/lib/nanoc2/extra/vcses/dummy.rb +20 -0
- data/lib/nanoc2/extra/vcses/git.rb +21 -0
- data/lib/nanoc2/extra/vcses/mercurial.rb +21 -0
- data/lib/nanoc2/extra/vcses/subversion.rb +21 -0
- data/lib/nanoc2/filters.rb +16 -0
- data/lib/nanoc2/filters/bluecloth.rb +13 -0
- data/lib/nanoc2/filters/erb.rb +19 -0
- data/lib/nanoc2/filters/erubis.rb +14 -0
- data/lib/nanoc2/filters/haml.rb +21 -0
- data/lib/nanoc2/filters/markaby.rb +14 -0
- data/lib/nanoc2/filters/maruku.rb +14 -0
- data/lib/nanoc2/filters/old.rb +19 -0
- data/lib/nanoc2/filters/rainpress.rb +13 -0
- data/lib/nanoc2/filters/rdiscount.rb +13 -0
- data/lib/nanoc2/filters/rdoc.rb +23 -0
- data/lib/nanoc2/filters/redcloth.rb +14 -0
- data/lib/nanoc2/filters/relativize_paths.rb +16 -0
- data/lib/nanoc2/filters/relativize_paths_in_css.rb +16 -0
- data/lib/nanoc2/filters/relativize_paths_in_html.rb +16 -0
- data/lib/nanoc2/filters/rubypants.rb +14 -0
- data/lib/nanoc2/filters/sass.rb +18 -0
- data/lib/nanoc2/helpers.rb +9 -0
- data/lib/nanoc2/helpers/blogging.rb +217 -0
- data/lib/nanoc2/helpers/capturing.rb +63 -0
- data/lib/nanoc2/helpers/filtering.rb +54 -0
- data/lib/nanoc2/helpers/html_escape.rb +25 -0
- data/lib/nanoc2/helpers/link_to.rb +113 -0
- data/lib/nanoc2/helpers/render.rb +49 -0
- data/lib/nanoc2/helpers/tagging.rb +56 -0
- data/lib/nanoc2/helpers/text.rb +38 -0
- data/lib/nanoc2/helpers/xml_sitemap.rb +63 -0
- data/lib/nanoc2/routers.rb +3 -0
- data/lib/nanoc2/routers/default.rb +54 -0
- data/lib/nanoc2/routers/no_dirs.rb +66 -0
- data/lib/nanoc2/routers/versioned.rb +79 -0
- metadata +185 -0
data/ChangeLog
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2007-2008 Denis Defreyne and contributors
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
== Overview
|
2
|
+
|
3
|
+
nanoc is a simple but very flexible static site generator written in Ruby.
|
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,
|
6
|
+
Markdown, etc.
|
7
|
+
|
8
|
+
== Documentation
|
9
|
+
|
10
|
+
nanoc's web site, which can be found at http://nanoc.stoneship.org, contains a
|
11
|
+
few useful resources to help you get started with nanoc:
|
12
|
+
|
13
|
+
* The tutorial at http://nanoc.stoneship.org/help/tutorial
|
14
|
+
* The manual at http://nanoc.stoneship.org/help/manual
|
15
|
+
|
16
|
+
It is probably also worth checking out and perhaps subscribing to the
|
17
|
+
discussion groups:
|
18
|
+
|
19
|
+
* The discussion group in English at http://groups.google.com/group/nanoc
|
20
|
+
* The discussion group in Spanish at http://groups.google.com/group/nanoc-es
|
21
|
+
|
22
|
+
=== Source Code Documentation
|
23
|
+
|
24
|
+
The source code is structured in a few directories:
|
25
|
+
|
26
|
+
* *bin* contains the commandline tool aptly named +nanoc+
|
27
|
+
* *lib*
|
28
|
+
* *nanoc*
|
29
|
+
* *base* contains the bare essentials necessary for nanoc to function
|
30
|
+
* *binary_filters* contains the standard binary filters
|
31
|
+
(Nanoc2::BinaryFilter subclasses) such as the thumbnail filter
|
32
|
+
* *cli* contains the commandline interface
|
33
|
+
* *data_sources* contains the standard data sources (Nanoc2::DataSource
|
34
|
+
subclasses), such as the filesystem data source
|
35
|
+
* *helpers* contains helpers, which provide functionality some sites
|
36
|
+
may find useful, such as the blogging and tagging helpers
|
37
|
+
* *extra* contains stuff that is not needed by nanoc itself, but which may
|
38
|
+
be used by helpers, data sources, filters or routers.
|
39
|
+
* *filters* contains the standard filters (Nanoc2::Filter subclasses) such
|
40
|
+
as ERB, Markdown, Haml, ...
|
41
|
+
* *routers* contains the standard routers (Nanoc2::Router subclasses)
|
42
|
+
* *test* contains test fixtures as well as testing code, structured in the
|
43
|
+
same way as lib/nanoc
|
44
|
+
|
45
|
+
The namespaces (modules) are organised like this:
|
46
|
+
|
47
|
+
* *Nanoc2* is the namespace for everything nanoc-related (obviously). The
|
48
|
+
classes in 'lib/nanoc2/base' are part of this module (not Nanoc2::Base
|
49
|
+
which does not exist)
|
50
|
+
* *BinaryFilters* contains the binary filters
|
51
|
+
* *CLI* containing everything related to the commandline tool.
|
52
|
+
* *DataSources* contains the data sources
|
53
|
+
* *Helpers* contains the helpers
|
54
|
+
* *Extra* contains useful stuff not needed by nanoc itself
|
55
|
+
* *Filters* contains the (textual) filters
|
56
|
+
* *Routers* contains the routers
|
57
|
+
|
58
|
+
The central class in nanoc is Nanoc2::Site, so you should start there if you
|
59
|
+
want to explore nanoc from a technical perspective.
|
60
|
+
|
61
|
+
== Contributors
|
62
|
+
|
63
|
+
(In alphabetical order)
|
64
|
+
|
65
|
+
* Colin Barrett
|
66
|
+
* Dmitry Bilunov
|
67
|
+
* Šime Ramov
|
68
|
+
* "Soryu"
|
69
|
+
* Dennis Sutch
|
70
|
+
|
71
|
+
Special thanks to Ale Muñoz.
|
72
|
+
|
73
|
+
== Contact
|
74
|
+
|
75
|
+
You can reach me at <denis.defreyne@stoneship.org>.
|
data/Rakefile
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
##### Requirements
|
2
|
+
|
3
|
+
# Rake etc
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/gempackagetask'
|
6
|
+
|
7
|
+
# nanoc itself
|
8
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/lib'))
|
9
|
+
require 'nanoc2'
|
10
|
+
|
11
|
+
##### General details
|
12
|
+
|
13
|
+
NAME = 'nanoc2'
|
14
|
+
VERS = Nanoc2::VERSION
|
15
|
+
SUMMARY = 'a tool that runs on your local computer and compiles ' +
|
16
|
+
'Markdown, Textile, Haml, ... documents into static web pages'
|
17
|
+
HOMEPAGE = 'http://nanoc.stoneship.org/'
|
18
|
+
|
19
|
+
AUTHOR = 'Denis Defreyne'
|
20
|
+
EMAIL = 'denis.defreyne@stoneship.org'
|
21
|
+
|
22
|
+
MESSAGE = <<EOS
|
23
|
+
Thanks for installing nanoc 2.2! Here are some resources to help you get started:
|
24
|
+
|
25
|
+
* The tutorial at <http://nanoc.stoneship.org/help/tutorial/>
|
26
|
+
* The manual at <http://nanoc.stoneship.org/help/manual/>
|
27
|
+
* The discussion group at <http://groups.google.com/group/nanoc>
|
28
|
+
|
29
|
+
Be sure to check out the nanoc blog at <http://nanoc.stoneship.org/blog/> for
|
30
|
+
details about this release.
|
31
|
+
|
32
|
+
Enjoy!
|
33
|
+
EOS
|
34
|
+
|
35
|
+
##### Packaging
|
36
|
+
|
37
|
+
GemSpec = Gem::Specification.new do |s|
|
38
|
+
s.name = NAME
|
39
|
+
s.version = VERS
|
40
|
+
s.platform = Gem::Platform::RUBY
|
41
|
+
s.summary = SUMMARY
|
42
|
+
s.description = s.summary
|
43
|
+
s.homepage = HOMEPAGE
|
44
|
+
|
45
|
+
s.author = AUTHOR
|
46
|
+
s.email = EMAIL
|
47
|
+
|
48
|
+
s.post_install_message = '-' * 78 + "\n" + MESSAGE + '-' * 78
|
49
|
+
|
50
|
+
s.rubyforge_project = 'nanoc'
|
51
|
+
|
52
|
+
s.required_ruby_version = '>= 1.8.5'
|
53
|
+
|
54
|
+
s.has_rdoc = true
|
55
|
+
s.extra_rdoc_files = [ 'README' ]
|
56
|
+
s.rdoc_options << '--title' << 'nanoc2' <<
|
57
|
+
'--main' << 'README' <<
|
58
|
+
'--charset' << 'utf-8' <<
|
59
|
+
'--exclude' << 'lib/nanoc2/cli/commands' <<
|
60
|
+
'--exclude' << 'lib/nanoc2/binary_filters' <<
|
61
|
+
'--exclude' << 'lib/nanoc2/extra/vcses' <<
|
62
|
+
'--exclude' << 'lib/nanoc2/filters' <<
|
63
|
+
'--exclude' << 'doc' <<
|
64
|
+
'--exclude' << 'test' <<
|
65
|
+
'--exclude' << 'vendor' <<
|
66
|
+
'--line-numbers'
|
67
|
+
|
68
|
+
s.files = %w( README LICENSE ChangeLog Rakefile ) + Dir[File.join('{bin,lib,vendor}', '**', '*')]
|
69
|
+
s.executables = [ 'nanoc2' ]
|
70
|
+
s.require_path = 'lib'
|
71
|
+
s.bindir = 'bin'
|
72
|
+
end
|
73
|
+
|
74
|
+
Dir.glob('tasks/**/*.rake').each { |r| Rake.application.add_import r }
|
75
|
+
|
76
|
+
task :default => [ :fetch_dependencies, :test ]
|
data/bin/nanoc2
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Add lib to load path
|
4
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
|
5
|
+
|
6
|
+
# Print deprecation warning
|
7
|
+
$stderr.puts <<-EOS
|
8
|
+
+----------------------------------------------------------------------------+
|
9
|
+
| WARNING: nanoc 2.x has been superseded by nanoc 3.x and is no longer main- |
|
10
|
+
| tained. There will be no future updates to nanoc 2.x. Consider upgrading |
|
11
|
+
| to nanoc 3.x. For more information, see the nanoc 2.x-to-3.x migration |
|
12
|
+
| guide at <http://nanoc.stoneship.org/migrating/>. |
|
13
|
+
+----------------------------------------------------------------------------+
|
14
|
+
EOS
|
15
|
+
$stderr.puts
|
16
|
+
|
17
|
+
# Load nanoc
|
18
|
+
require 'nanoc2'
|
19
|
+
require 'nanoc2/cli'
|
20
|
+
|
21
|
+
# Load custom code that can't be load later
|
22
|
+
Dir['lib/commands/*.rb'].each { |f| require f }
|
23
|
+
Dir['lib/data_sources/*.rb'].each { |f| require f }
|
24
|
+
|
25
|
+
# Run base
|
26
|
+
Nanoc2::CLI::Base.new.run(ARGV)
|
data/lib/nanoc2.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
module Nanoc2
|
2
|
+
|
3
|
+
# The current nanoc version.
|
4
|
+
VERSION = '2.2.3'
|
5
|
+
|
6
|
+
# Generic error. Superclass for all nanoc-specific errors.
|
7
|
+
class Error < RuntimeError ; end
|
8
|
+
|
9
|
+
module Errors # :nodoc:
|
10
|
+
|
11
|
+
# Error that is raised when a site is loaded that uses a data source with
|
12
|
+
# an unknown identifier.
|
13
|
+
class UnknownDataSourceError < Error ; end
|
14
|
+
|
15
|
+
# Error that is raised when a site is loaded that uses a data source with
|
16
|
+
# an unknown identifier.
|
17
|
+
class UnknownRouterError < Error ; end
|
18
|
+
|
19
|
+
# Error that is raised during site compilation when a page uses a layout
|
20
|
+
# that is not present in the site.
|
21
|
+
class UnknownLayoutError < Error ; end
|
22
|
+
|
23
|
+
# Error that is raised during site compilation when a page uses a filter
|
24
|
+
# that is not known.
|
25
|
+
class UnknownFilterError < Error ; end
|
26
|
+
|
27
|
+
# Error that is raised during site compilation when a layout is compiled
|
28
|
+
# for which the filter cannot be determined. This is similar to the
|
29
|
+
# UnknownFilterError, but specific for filters for layouts.
|
30
|
+
class CannotDetermineFilterError < Error ; end
|
31
|
+
|
32
|
+
# Error that is raised during site compilation when a page (directly or
|
33
|
+
# indirectly) includes its own page content, leading to endless recursion.
|
34
|
+
class RecursiveCompilationError < Error ; end
|
35
|
+
|
36
|
+
# Error that is raised when a certain function or feature is used that is
|
37
|
+
# no longer supported by nanoc.
|
38
|
+
class NoLongerSupportedError < Error ; end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
module BinaryFilters # :nodoc:
|
43
|
+
end
|
44
|
+
|
45
|
+
module DataSources # :nodoc:
|
46
|
+
end
|
47
|
+
|
48
|
+
module Helpers # :nodoc:
|
49
|
+
end
|
50
|
+
|
51
|
+
module Extra # :nodoc:
|
52
|
+
end
|
53
|
+
|
54
|
+
module Filters # :nodoc:
|
55
|
+
end
|
56
|
+
|
57
|
+
module Routers # :nodoc:
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
# Load requirements
|
63
|
+
require 'yaml'
|
64
|
+
require 'fileutils'
|
65
|
+
|
66
|
+
# Load nanoc
|
67
|
+
require 'nanoc2/base'
|
68
|
+
require 'nanoc2/extra'
|
69
|
+
require 'nanoc2/data_sources'
|
70
|
+
require 'nanoc2/binary_filters'
|
71
|
+
require 'nanoc2/filters'
|
72
|
+
require 'nanoc2/routers'
|
73
|
+
require 'nanoc2/helpers'
|
data/lib/nanoc2/base.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Nanoc2
|
2
|
+
|
3
|
+
autoload :Asset, 'nanoc2/base/asset'
|
4
|
+
autoload :AssetDefaults, 'nanoc2/base/asset_defaults'
|
5
|
+
autoload :AssetRep, 'nanoc2/base/asset_rep'
|
6
|
+
autoload :BinaryFilter, 'nanoc2/base/binary_filter'
|
7
|
+
autoload :Code, 'nanoc2/base/code'
|
8
|
+
autoload :Compiler, 'nanoc2/base/compiler'
|
9
|
+
autoload :DataSource, 'nanoc2/base/data_source'
|
10
|
+
autoload :Defaults, 'nanoc2/base/defaults'
|
11
|
+
autoload :Filter, 'nanoc2/base/filter'
|
12
|
+
autoload :Layout, 'nanoc2/base/layout'
|
13
|
+
autoload :NotificationCenter, 'nanoc2/base/notification_center'
|
14
|
+
autoload :Page, 'nanoc2/base/page'
|
15
|
+
autoload :PageDefaults, 'nanoc2/base/page_defaults'
|
16
|
+
autoload :PageRep, 'nanoc2/base/page_rep'
|
17
|
+
autoload :Plugin, 'nanoc2/base/plugin'
|
18
|
+
autoload :Proxy, 'nanoc2/base/proxy'
|
19
|
+
autoload :Router, 'nanoc2/base/router'
|
20
|
+
autoload :Site, 'nanoc2/base/site'
|
21
|
+
autoload :Template, 'nanoc2/base/template'
|
22
|
+
|
23
|
+
require 'nanoc2/base/core_ext'
|
24
|
+
require 'nanoc2/base/proxies'
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module Nanoc2
|
2
|
+
|
3
|
+
# A Nanoc2::Asset represents an asset in a nanoc site. It has a file object
|
4
|
+
# (File instance) and attributes, as well as a path. It can also store the
|
5
|
+
# modification time to speed up compilation.
|
6
|
+
#
|
7
|
+
# Each asset has a list of asset representations or reps (Nanoc2::AssetRep);
|
8
|
+
# compiling an asset actually compiles all of its assets.
|
9
|
+
class Asset
|
10
|
+
|
11
|
+
# Defaults values for assets.
|
12
|
+
DEFAULTS = {
|
13
|
+
:extension => 'dat',
|
14
|
+
:binary => true,
|
15
|
+
:filters => []
|
16
|
+
}
|
17
|
+
|
18
|
+
# The Nanoc2::Site this asset belongs to.
|
19
|
+
attr_accessor :site
|
20
|
+
|
21
|
+
# This assets's file.
|
22
|
+
attr_reader :file
|
23
|
+
|
24
|
+
# A hash containing this asset's attributes.
|
25
|
+
attr_accessor :attributes
|
26
|
+
|
27
|
+
# This asset's path.
|
28
|
+
attr_reader :path
|
29
|
+
|
30
|
+
# The time when this asset was last modified.
|
31
|
+
attr_reader :mtime
|
32
|
+
|
33
|
+
# This asset's list of asset representations.
|
34
|
+
attr_reader :reps
|
35
|
+
|
36
|
+
# Creates a new asset.
|
37
|
+
#
|
38
|
+
# +file+:: An instance of File representing the uncompiled asset.
|
39
|
+
#
|
40
|
+
# +attributes+:: A hash containing this asset's attributes.
|
41
|
+
#
|
42
|
+
# +path+:: This asset's path.
|
43
|
+
#
|
44
|
+
# +mtime+:: The time when this asset was last modified.
|
45
|
+
def initialize(file, attributes, path, mtime=nil)
|
46
|
+
# Set primary attributes
|
47
|
+
@file = file
|
48
|
+
@attributes = attributes.clean
|
49
|
+
@path = path.cleaned_path
|
50
|
+
@mtime = mtime
|
51
|
+
end
|
52
|
+
|
53
|
+
# Builds the individual asset representations (Nanoc2::AssetRep) for this
|
54
|
+
# asset.
|
55
|
+
def build_reps
|
56
|
+
# Get list of rep names
|
57
|
+
rep_names_default = (@site.asset_defaults.attributes[:reps] || {}).keys
|
58
|
+
rep_names_this = (@attributes[:reps] || {}).keys + [ :default ]
|
59
|
+
rep_names = rep_names_default | rep_names_this
|
60
|
+
|
61
|
+
# Get list of reps
|
62
|
+
reps = rep_names.inject({}) do |memo, rep_name|
|
63
|
+
rep = (@attributes[:reps] || {})[rep_name]
|
64
|
+
is_bad = (@attributes[:reps] || {}).has_key?(rep_name) && rep.nil?
|
65
|
+
is_bad ? memo : memo.merge(rep_name => rep || {})
|
66
|
+
end
|
67
|
+
|
68
|
+
# Build reps
|
69
|
+
@reps = []
|
70
|
+
reps.each_pair do |name, attrs|
|
71
|
+
@reps << AssetRep.new(self, attrs, name)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns a proxy (Nanoc2::AssetProxy) for this asset.
|
76
|
+
def to_proxy
|
77
|
+
@proxy ||= AssetProxy.new(self)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns the attribute with the given name.
|
81
|
+
def attribute_named(name)
|
82
|
+
return @attributes[name] if @attributes.has_key?(name)
|
83
|
+
return @site.asset_defaults.attributes[name] if @site.asset_defaults.attributes.has_key?(name)
|
84
|
+
return DEFAULTS[name]
|
85
|
+
end
|
86
|
+
|
87
|
+
# Saves the asset in the database, creating it if it doesn't exist yet or
|
88
|
+
# updating it if it already exists. Tells the site's data source to save
|
89
|
+
# the asset.
|
90
|
+
def save
|
91
|
+
@site.data_source.loading do
|
92
|
+
@site.data_source.save_asset(self)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Moves the asset to a new path. Tells the site's data source to move the
|
97
|
+
# asset.
|
98
|
+
def move_to(new_path)
|
99
|
+
@site.data_source.loading do
|
100
|
+
@site.data_source.move_asset(self, new_path)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Deletes the asset. Tells the site's data source to delete the asset.
|
105
|
+
def delete
|
106
|
+
@site.data_source.loading do
|
107
|
+
@site.data_source.delete_asset(self)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def inspect
|
112
|
+
"<#{self.class} path=#{self.path}>"
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Nanoc2
|
2
|
+
|
3
|
+
# Nanoc2::AssetDefaults represent the default attributes for all assets in
|
4
|
+
# the site. If a specific asset attribute is requested, but not found, then
|
5
|
+
# the asset defaults will be queried for this attribute. (If the attribute
|
6
|
+
# doesn't even exist in the asset defaults, hardcoded defaults will be
|
7
|
+
# used.)
|
8
|
+
class AssetDefaults < Defaults
|
9
|
+
|
10
|
+
# Saves the asset defaults in the database, creating it if it doesn't
|
11
|
+
# exist yet or updating it if it already exists. Tells the site's data
|
12
|
+
# source to save the asset defaults.
|
13
|
+
def save
|
14
|
+
@site.data_source.loading do
|
15
|
+
@site.data_source.save_asset_defaults(self)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|