nanoc 2.0.4 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +31 -1
- data/LICENSE +1 -1
- data/README +63 -3
- data/Rakefile +59 -12
- data/bin/nanoc +7 -199
- data/lib/nanoc.rb +83 -12
- data/lib/nanoc/base/asset.rb +113 -0
- data/lib/nanoc/base/asset_defaults.rb +21 -0
- data/lib/nanoc/base/asset_rep.rb +277 -0
- data/lib/nanoc/base/binary_filter.rb +44 -0
- data/lib/nanoc/base/code.rb +41 -0
- data/lib/nanoc/base/compiler.rb +46 -34
- data/lib/nanoc/base/core_ext/hash.rb +51 -7
- data/lib/nanoc/base/core_ext/string.rb +8 -0
- data/lib/nanoc/base/data_source.rb +253 -20
- data/lib/nanoc/base/defaults.rb +30 -0
- data/lib/nanoc/base/enhancements.rb +9 -84
- data/lib/nanoc/base/filter.rb +109 -6
- data/lib/nanoc/base/layout.rb +91 -0
- data/lib/nanoc/base/notification_center.rb +66 -0
- data/lib/nanoc/base/page.rb +94 -126
- data/lib/nanoc/base/page_defaults.rb +20 -0
- data/lib/nanoc/base/page_rep.rb +318 -0
- data/lib/nanoc/base/plugin.rb +57 -9
- data/lib/nanoc/base/proxies/asset_proxy.rb +29 -0
- data/lib/nanoc/base/proxies/asset_rep_proxy.rb +26 -0
- data/lib/nanoc/base/proxies/layout_proxy.rb +25 -0
- data/lib/nanoc/base/proxies/page_proxy.rb +35 -0
- data/lib/nanoc/base/proxies/page_rep_proxy.rb +28 -0
- data/lib/nanoc/base/proxy.rb +37 -0
- data/lib/nanoc/base/router.rb +72 -0
- data/lib/nanoc/base/site.rb +219 -88
- data/lib/nanoc/base/template.rb +64 -0
- data/lib/nanoc/binary_filters/image_science_thumbnail.rb +28 -0
- data/lib/nanoc/cli.rb +1 -0
- data/lib/nanoc/cli/base.rb +219 -0
- data/lib/nanoc/cli/cli.rb +16 -0
- data/lib/nanoc/cli/command.rb +105 -0
- data/lib/nanoc/cli/commands/autocompile.rb +80 -0
- data/lib/nanoc/cli/commands/compile.rb +273 -0
- data/lib/nanoc/cli/commands/create_layout.rb +85 -0
- data/lib/nanoc/cli/commands/create_page.rb +85 -0
- data/lib/nanoc/cli/commands/create_site.rb +327 -0
- data/lib/nanoc/cli/commands/create_template.rb +76 -0
- data/lib/nanoc/cli/commands/help.rb +69 -0
- data/lib/nanoc/cli/commands/info.rb +114 -0
- data/lib/nanoc/cli/commands/switch.rb +141 -0
- data/lib/nanoc/cli/commands/update.rb +91 -0
- data/lib/nanoc/cli/ext.rb +37 -0
- data/lib/nanoc/cli/logger.rb +66 -0
- data/lib/nanoc/cli/option_parser.rb +168 -0
- data/lib/nanoc/data_sources/filesystem.rb +645 -224
- data/lib/nanoc/data_sources/filesystem_combined.rb +495 -0
- data/lib/nanoc/extra/auto_compiler.rb +265 -0
- data/lib/nanoc/extra/context.rb +22 -0
- data/lib/nanoc/extra/core_ext/hash.rb +54 -0
- data/lib/nanoc/extra/core_ext/time.rb +13 -0
- data/lib/nanoc/extra/file_proxy.rb +29 -0
- data/lib/nanoc/extra/vcs.rb +48 -0
- data/lib/nanoc/extra/vcses/bazaar.rb +21 -0
- data/lib/nanoc/extra/vcses/dummy.rb +20 -0
- data/lib/nanoc/extra/vcses/git.rb +21 -0
- data/lib/nanoc/extra/vcses/mercurial.rb +21 -0
- data/lib/nanoc/extra/vcses/subversion.rb +21 -0
- data/lib/nanoc/filters/bluecloth.rb +13 -0
- data/lib/nanoc/filters/erb.rb +6 -22
- data/lib/nanoc/filters/erubis.rb +14 -0
- data/lib/nanoc/filters/haml.rb +7 -23
- data/lib/nanoc/filters/markaby.rb +5 -5
- data/lib/nanoc/filters/maruku.rb +14 -0
- data/lib/nanoc/filters/old.rb +19 -0
- data/lib/nanoc/filters/rdiscount.rb +13 -0
- data/lib/nanoc/filters/rdoc.rb +5 -4
- data/lib/nanoc/filters/redcloth.rb +14 -0
- data/lib/nanoc/filters/rubypants.rb +14 -0
- data/lib/nanoc/filters/sass.rb +13 -0
- data/lib/nanoc/helpers/blogging.rb +170 -0
- data/lib/nanoc/helpers/capturing.rb +59 -0
- data/lib/nanoc/helpers/html_escape.rb +23 -0
- data/lib/nanoc/helpers/link_to.rb +69 -0
- data/lib/nanoc/helpers/render.rb +47 -0
- data/lib/nanoc/helpers/tagging.rb +52 -0
- data/lib/nanoc/helpers/xml_sitemap.rb +58 -0
- data/lib/nanoc/routers/default.rb +54 -0
- data/lib/nanoc/routers/no_dirs.rb +66 -0
- data/lib/nanoc/routers/versioned.rb +79 -0
- metadata +112 -22
- data/lib/nanoc/base/auto_compiler.rb +0 -132
- data/lib/nanoc/base/layout_processor.rb +0 -33
- data/lib/nanoc/base/page_proxy.rb +0 -31
- data/lib/nanoc/base/plugin_manager.rb +0 -33
- data/lib/nanoc/data_sources/database.rb +0 -259
- data/lib/nanoc/data_sources/trivial.rb +0 -145
- data/lib/nanoc/filters/markdown.rb +0 -13
- data/lib/nanoc/filters/smartypants.rb +0 -13
- data/lib/nanoc/filters/textile.rb +0 -13
- data/lib/nanoc/layout_processors/erb.rb +0 -35
- data/lib/nanoc/layout_processors/haml.rb +0 -38
- data/lib/nanoc/layout_processors/markaby.rb +0 -16
@@ -1,145 +0,0 @@
|
|
1
|
-
# This is the module where the trivial data source will live in. It's not
|
2
|
-
# really _necessary_ to create a separate module/namespace for each data
|
3
|
-
# source, but it can be useful, especially when the data source needs extra
|
4
|
-
# classes (for example, the database data source defines uses ActiveRecord, so
|
5
|
-
# it needs classes for each table).
|
6
|
-
module Nanoc::DataSource::Trivial
|
7
|
-
|
8
|
-
# This is the implementation of a trivial data source. It doesn't do much
|
9
|
-
# except return bogus data. It is meant to be a very simple example of a
|
10
|
-
# data source, and it should be quite useful for those who want to write
|
11
|
-
# their own data sources.
|
12
|
-
class TrivialDataSource < Nanoc::DataSource
|
13
|
-
|
14
|
-
########## Attributes ##########
|
15
|
-
|
16
|
-
# DataSource.identifier defines the name for this data source. The first
|
17
|
-
# and only argument is the data source name as a symbol.
|
18
|
-
identifier :trivial
|
19
|
-
|
20
|
-
########## Preparation ##########
|
21
|
-
|
22
|
-
# DataSource#up is run before compiling. This is the place where you
|
23
|
-
# should initialize the data source, if necessary. You don't need to
|
24
|
-
# implement it; you can leave it out if you don't need initialization.
|
25
|
-
# This is the ideal place to connect to the database, for example.
|
26
|
-
# If your data source requires any special libraries, require them here
|
27
|
-
# using 'nanoc_require'.
|
28
|
-
def up
|
29
|
-
end
|
30
|
-
|
31
|
-
# DataSource#down is run after compiling. This is where you should clean
|
32
|
-
# up any resources you used during the site compilation. You don't need to
|
33
|
-
# implement it; you can leave it out if there's nothing to clean up. For
|
34
|
-
# example, this is a good place to close the connection to the database,
|
35
|
-
# if you have one.
|
36
|
-
def down
|
37
|
-
end
|
38
|
-
|
39
|
-
# DataSource#setup is run when the site is created. This is the place
|
40
|
-
# where you should create the data source for the first time. You don't
|
41
|
-
# need to implement it; you can leave it out if there's nothing to set up.
|
42
|
-
# For example, if you're using a database, this is where you should create
|
43
|
-
# the necessary tables for the data source to function properly.
|
44
|
-
def setup
|
45
|
-
error "Sorry. The trivial data source isn't competent enough."
|
46
|
-
end
|
47
|
-
|
48
|
-
########## Loading data ##########
|
49
|
-
|
50
|
-
# DataSource#pages returns an array of hashes that represent pages. Each
|
51
|
-
# hash must have at least the :uncompiled_content and :path keys. You can
|
52
|
-
# include other metadata in this hash, though.
|
53
|
-
def pages
|
54
|
-
[
|
55
|
-
{ :uncompiled_content => 'Hi!', :path => '/' },
|
56
|
-
{ :uncompiled_content => 'Hello there.', :path => '/about/' }
|
57
|
-
]
|
58
|
-
end
|
59
|
-
|
60
|
-
# Datasource#page_defaults returns a hash with default values for page
|
61
|
-
# metadata. This hash can be anything, even an empty hash if you wish.
|
62
|
-
def page_defaults
|
63
|
-
{ :layout => 'quux' }
|
64
|
-
end
|
65
|
-
|
66
|
-
# DataSource#layouts returns an array of hashes that represent layouts.
|
67
|
-
# Each hash must have the :name, :content and :extension keys. The
|
68
|
-
# :extension key determines the layout processor that will be used (they
|
69
|
-
# are defined in layout_processors/*.rb).
|
70
|
-
def layouts
|
71
|
-
[
|
72
|
-
{
|
73
|
-
:name => 'quux',
|
74
|
-
:content => "<html>\n" +
|
75
|
-
" <head>\n" +
|
76
|
-
" <title><%= @page.title %></title>\n" +
|
77
|
-
" </head>\n" +
|
78
|
-
" <body>\n" +
|
79
|
-
"<%= @page.content %>\n" +
|
80
|
-
" </body>\n" +
|
81
|
-
"</html>",
|
82
|
-
:extension => '.erb'
|
83
|
-
}
|
84
|
-
]
|
85
|
-
end
|
86
|
-
|
87
|
-
# DataSource#templates returns an array of hashes that represent page
|
88
|
-
# templates. These page templates are used used by DataSource#create_page
|
89
|
-
# to create pages using a template. Each hash must have the :name key for
|
90
|
-
# identifying the template. Apart from that, you can structure the hash
|
91
|
-
# like you desire. I recommend having :content (for the page content) and
|
92
|
-
# :meta (for the page metadata) keys. Note that in this example, the value
|
93
|
-
# corresponding to the :meta key is a hash, but it could just as well have
|
94
|
-
# been a YAML-formatted string. Just make sure that what
|
95
|
-
# DataSource#templates serves is what DataSource#create_page expects.
|
96
|
-
def templates
|
97
|
-
[
|
98
|
-
{
|
99
|
-
:name => 'default',
|
100
|
-
:content => 'Hi, I am a new page. Please edit me!',
|
101
|
-
:meta => { :title => 'A New Page' }
|
102
|
-
}
|
103
|
-
]
|
104
|
-
end
|
105
|
-
|
106
|
-
# DataSource#code returns a string containing custom code which will be
|
107
|
-
# loaded before the site is compiled. This can be code for custom filters
|
108
|
-
# and layout processors, but pretty much any code can be put in there
|
109
|
-
# (global helper functions are very useful). It is possible to override
|
110
|
-
# methods of built-in nanoc classes, but doing so will likely cause
|
111
|
-
# massive breakage, so doing so is not recommended.
|
112
|
-
def code
|
113
|
-
"def foo ; 'bar' ; end"
|
114
|
-
end
|
115
|
-
|
116
|
-
########## Creating data ##########
|
117
|
-
|
118
|
-
# DataSource#create_page is run when a page is created. This function
|
119
|
-
# should create a new page with the given name and using the given
|
120
|
-
# template. The template is a hash taken the array of hashes returned by
|
121
|
-
# DataSource#templates, so make sure that what DataSource#templates
|
122
|
-
# returns is what DataSource#create_page expects. This trivial data source
|
123
|
-
# doesn't have a permanent storage, so it can't create any pages.
|
124
|
-
def create_page(path, template)
|
125
|
-
error "Sorry. The trivial data source isn't competent enough."
|
126
|
-
end
|
127
|
-
|
128
|
-
# DataSource#create_layout is run when a layout is created. This function
|
129
|
-
# should create a new layout with the given name. This trivial data source
|
130
|
-
# doesn't have a permanent storage, so it can't create any layouts.
|
131
|
-
def create_layout(name)
|
132
|
-
error "Sorry. The trivial data source isn't competent enough."
|
133
|
-
end
|
134
|
-
|
135
|
-
# DataSource#create_template is run when a template is created. This
|
136
|
-
# function should create a new template with the given name. This trivial
|
137
|
-
# data source doesn't have a permanent storage, so it can't create any
|
138
|
-
# templates.
|
139
|
-
def create_template(name)
|
140
|
-
error "Sorry. The trivial data source isn't competent enough."
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Nanoc::LayoutProcessor::ERB
|
2
|
-
|
3
|
-
class ERBContext
|
4
|
-
|
5
|
-
def initialize(hash)
|
6
|
-
hash.each_pair do |key, value|
|
7
|
-
instance_variable_set('@' + key.to_s, value)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_binding
|
12
|
-
binding
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
class ERBLayoutProcessor < Nanoc::LayoutProcessor
|
18
|
-
|
19
|
-
identifiers :erb, :eruby
|
20
|
-
extensions '.erb', '.rhtml'
|
21
|
-
|
22
|
-
def run(layout)
|
23
|
-
nanoc_require 'erb'
|
24
|
-
|
25
|
-
# Create context
|
26
|
-
assigns = @other_assigns.merge({ :page => @page, :pages => @pages, :config => @config, :site => @site })
|
27
|
-
context = ERBContext.new(assigns)
|
28
|
-
|
29
|
-
# Get result
|
30
|
-
::ERB.new(layout).result(context.get_binding)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Nanoc::LayoutProcessor::Haml
|
2
|
-
|
3
|
-
class Context
|
4
|
-
|
5
|
-
def initialize(hash)
|
6
|
-
hash.each_pair do |key, value|
|
7
|
-
instance_variable_set('@' + key.to_s, value)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_binding
|
12
|
-
binding
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
class HamlLayoutProcessor < Nanoc::LayoutProcessor
|
18
|
-
|
19
|
-
identifiers :haml
|
20
|
-
extensions '.haml'
|
21
|
-
|
22
|
-
def run(content)
|
23
|
-
nanoc_require 'haml'
|
24
|
-
|
25
|
-
# Get options
|
26
|
-
options = @page.haml_options || {}
|
27
|
-
|
28
|
-
# Get assigns/locals
|
29
|
-
assigns = { :page => @page, :pages => @pages, :config => @config, :site => @site }
|
30
|
-
context = Context.new(assigns)
|
31
|
-
|
32
|
-
# Get result
|
33
|
-
::Haml::Engine.new(content, options).render(context, assigns)
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Nanoc::LayoutProcessor::Markaby
|
2
|
-
class MarkabyLayoutProcessor < Nanoc::LayoutProcessor
|
3
|
-
|
4
|
-
identifiers :markaby
|
5
|
-
extensions '.mab'
|
6
|
-
|
7
|
-
def run(layout)
|
8
|
-
nanoc_require 'markaby'
|
9
|
-
|
10
|
-
assigns = @other_assigns.merge({ :page => @page, :pages => @pages, :config => @config, :site => @site })
|
11
|
-
|
12
|
-
::Markaby::Builder.new(assigns).instance_eval(layout).to_s
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|