nanoc 1.0.1 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/lib/compiler.rb +21 -63
- data/lib/creator.rb +21 -17
- data/lib/enhancements.rb +53 -38
- data/lib/nanoc.rb +6 -6
- metadata +4 -7
- data/test/test_compile.rb +0 -26
- data/test/test_create.rb +0 -71
- data/test/test_enhancements.rb +0 -114
data/Rakefile
CHANGED
@@ -10,14 +10,14 @@ require File.dirname(__FILE__) + '/lib/nanoc.rb'
|
|
10
10
|
|
11
11
|
NAME = 'nanoc'
|
12
12
|
VERS = Nanoc::VERSION
|
13
|
-
SUMMARY = 'a CMS that doesn\'t
|
13
|
+
SUMMARY = 'a CMS that doesn\'t run on your server'
|
14
14
|
|
15
15
|
HOMEPAGE = 'http://stoneship.org/software/nanoc'
|
16
16
|
EMAIL = 'denis.defreyne@stoneship.org'
|
17
17
|
|
18
18
|
#####
|
19
19
|
|
20
|
-
CLEAN.include [ '*.gem', 'pkg', 'tmp' ]
|
20
|
+
CLEAN.include [ '*.gem', 'pkg', 'tmp', 'test/fixtures/*/output/*' ]
|
21
21
|
|
22
22
|
spec = Gem::Specification.new do |s|
|
23
23
|
s.name = NAME
|
@@ -32,7 +32,7 @@ spec = Gem::Specification.new do |s|
|
|
32
32
|
s.required_ruby_version = '>= 1.8.2'
|
33
33
|
|
34
34
|
s.has_rdoc = false
|
35
|
-
s.files = %w( README LICENSE Rakefile ) + Dir.glob('{bin,lib
|
35
|
+
s.files = %w( README LICENSE Rakefile ) + Dir.glob('{bin,lib}/**/*')
|
36
36
|
s.executables = [ 'nanoc' ]
|
37
37
|
s.require_path = 'lib'
|
38
38
|
s.bindir = 'bin'
|
data/lib/compiler.rb
CHANGED
@@ -1,96 +1,54 @@
|
|
1
1
|
module Nanoc
|
2
|
-
|
3
2
|
class Compiler
|
4
3
|
|
5
|
-
DEFAULT_CONFIG
|
6
|
-
|
7
|
-
}
|
8
|
-
|
9
|
-
DEFAULT_PAGE = {
|
10
|
-
:layout => '<%= @content %>',
|
11
|
-
:filters => [],
|
12
|
-
:order => 0,
|
13
|
-
:extension => 'html'
|
14
|
-
}
|
4
|
+
DEFAULT_CONFIG = { :output_dir => 'output' }
|
5
|
+
DEFAULT_PAGE = { :filters => [], :extension => 'html', :order => 0, :layout => "default" }
|
15
6
|
|
16
7
|
def initialize
|
17
8
|
Nanoc.ensure_in_site
|
18
|
-
|
19
|
-
@config
|
20
|
-
@global_page
|
21
|
-
@default_layout = File.read_file('layouts/' + @global_page[:layout] + '.erb')
|
9
|
+
|
10
|
+
@config = DEFAULT_CONFIG.merge(YAML.load_file_and_clean('config.yaml'))
|
11
|
+
@global_page = DEFAULT_PAGE.merge(YAML.load_file_and_clean('meta.yaml'))
|
22
12
|
end
|
23
13
|
|
24
14
|
def run
|
25
|
-
Nanoc.ensure_in_site
|
26
|
-
|
27
|
-
# Require files in lib/
|
28
15
|
Dir.glob('lib/*.rb').each { |f| require f }
|
29
16
|
|
30
|
-
|
31
|
-
pages = uncompiled_pages.sort { |x,y| x[:order].to_i <=> y[:order].to_i }
|
32
|
-
pages = compile_pages(pages)
|
33
|
-
|
34
|
-
# Put pages in their layout
|
17
|
+
pages = compile_pages(uncompiled_pages)
|
35
18
|
pages.each do |page|
|
36
|
-
|
37
|
-
FileManager.create_file(path_for_page(page)) {
|
19
|
+
content = (page[:layout].nil? ? '<%= @page[:content] %>' : File.read("layouts/#{page[:layout]}.erb")).eruby(page.merge({ :page => page, :pages => pages }))
|
20
|
+
FileManager.create_file(path_for_page(page)) { content }
|
38
21
|
end
|
39
22
|
end
|
40
23
|
|
41
24
|
private
|
42
25
|
|
43
26
|
def uncompiled_pages
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
# Read all meta files
|
48
|
-
pages = meta_filenames.collect do |filename|
|
49
|
-
# Get meta file
|
50
|
-
page = @global_page.merge(File.read_clean_yaml(filename)).merge({:path => filename.sub(/^content/, '').sub('meta.yaml', '')})
|
27
|
+
Dir.glob('content/**/meta.yaml').collect do |filename|
|
28
|
+
page = @global_page.merge(YAML.load_file_and_clean(filename))
|
29
|
+
page[:path] = filename.sub(/^content/, '').sub('meta.yaml', '')
|
51
30
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
page[:
|
31
|
+
content_filenames = Dir.glob(filename.sub('meta.yaml', File.basename(File.dirname(filename)) + '.*'))
|
32
|
+
content_filenames += Dir.glob("#{File.dirname(filename)}/index.*") # fallback for nanoc 1.0
|
33
|
+
content_filenames.ensure_single('content files', File.dirname(filename))
|
34
|
+
page[:_content_filename] = content_filenames[0]
|
56
35
|
|
57
36
|
page
|
37
|
+
end.compact.reject { |page| page[:is_draft] }.sort do |x,y|
|
38
|
+
x[:order].to_i == y[:order].to_i ? x[:path] <=> y[:path] : x[:order].to_i <=> y[:order].to_i
|
58
39
|
end
|
59
40
|
end
|
60
41
|
|
61
42
|
def path_for_page(a_page)
|
62
|
-
|
63
|
-
@config[:output_dir] + a_page[:path] + 'index.' + a_page[:extension]
|
64
|
-
else
|
65
|
-
@config[:output_dir] + a_page[:custom_path]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def layout_for_page(a_page)
|
70
|
-
if a_page[:layout] == 'none'
|
71
|
-
'<%= @content %>'
|
72
|
-
elsif @global_page[:layout] != a_page[:layout]
|
73
|
-
File.read_file('layouts/' + a_page[:layout] + '.erb')
|
74
|
-
else
|
75
|
-
@default_layout
|
76
|
-
end
|
43
|
+
@config[:output_dir] + ( a_page[:custom_path].nil? ? a_page[:path] + 'index.' + a_page[:extension] : a_page[:custom_path] )
|
77
44
|
end
|
78
45
|
|
79
46
|
def compile_pages(a_pages)
|
80
|
-
pages
|
81
|
-
|
82
|
-
|
83
|
-
# Read and filter page
|
84
|
-
content = File.read_file(page[:_index_filename])
|
85
|
-
content.filter!(page[:filters], :eruby_context => { :pages => pages }) unless page[:filters].nil?
|
86
|
-
|
87
|
-
# Store page
|
88
|
-
pages << page.merge( { :content => content })
|
47
|
+
a_pages.inject([]) do |pages, page|
|
48
|
+
content = File.read(page[:_content_filename]).filter(page[:filters], :eruby_context => { :page => page, :pages => pages })
|
49
|
+
pages + [ page.merge( { :content => content }) ]
|
89
50
|
end
|
90
|
-
|
91
|
-
pages
|
92
51
|
end
|
93
52
|
|
94
53
|
end
|
95
|
-
|
96
54
|
end
|
data/lib/creator.rb
CHANGED
@@ -7,7 +7,7 @@ module Nanoc
|
|
7
7
|
FileManager.create_dir 'output'
|
8
8
|
|
9
9
|
FileManager.create_file 'config.yaml' do
|
10
|
-
"output_dir: output\n"
|
10
|
+
"output_dir: \"output\"\n"
|
11
11
|
end
|
12
12
|
|
13
13
|
FileManager.create_file 'meta.yaml' do
|
@@ -15,9 +15,10 @@ module Nanoc
|
|
15
15
|
"# Other metafiles can override the contents of this one.\n" +
|
16
16
|
"\n" +
|
17
17
|
"# Built-in\n" +
|
18
|
-
"layout:
|
19
|
-
"order:
|
20
|
-
"filters:
|
18
|
+
"layout: \"default\"\n" +
|
19
|
+
"order: 0\n" +
|
20
|
+
"filters: []\n" +
|
21
|
+
"extension: \"html\"\n" +
|
21
22
|
"\n" +
|
22
23
|
"# Custom\n"
|
23
24
|
end
|
@@ -34,10 +35,10 @@ module Nanoc
|
|
34
35
|
FileManager.create_file 'default.erb' do
|
35
36
|
"<html>\n" +
|
36
37
|
" <head>\n" +
|
37
|
-
" <title><%= @title %></title>\n" +
|
38
|
+
" <title><%= @page[:title] %></title>\n" +
|
38
39
|
" </head>\n" +
|
39
40
|
" <body>\n" +
|
40
|
-
"<%= @content %>\n" +
|
41
|
+
"<%= @page[:content] %>\n" +
|
41
42
|
" </body>\n" +
|
42
43
|
"</html>\n"
|
43
44
|
end
|
@@ -65,7 +66,7 @@ module Nanoc
|
|
65
66
|
|
66
67
|
FileManager.create_dir 'templates' do
|
67
68
|
FileManager.create_dir 'default' do
|
68
|
-
FileManager.create_file
|
69
|
+
FileManager.create_file "default.txt" do
|
69
70
|
"This is a new page. Please edit me!\n"
|
70
71
|
end
|
71
72
|
FileManager.create_file 'meta.yaml' do
|
@@ -78,7 +79,7 @@ module Nanoc
|
|
78
79
|
end
|
79
80
|
|
80
81
|
FileManager.create_dir 'content' do
|
81
|
-
FileManager.create_file '
|
82
|
+
FileManager.create_file 'content.txt' do
|
82
83
|
"This is a sample root page. Please edit me!\n"
|
83
84
|
end
|
84
85
|
FileManager.create_file 'meta.yaml' do
|
@@ -93,23 +94,26 @@ module Nanoc
|
|
93
94
|
|
94
95
|
def self.create_page(a_pagename, a_params={})
|
95
96
|
Nanoc.ensure_in_site
|
96
|
-
|
97
|
+
|
97
98
|
# Sanitize page name
|
98
99
|
if a_pagename =~ /^[\/\.]+/
|
99
|
-
$stderr.puts 'ERROR: page name starts with dots and/or slashes, aborting'
|
100
|
+
$stderr.puts 'ERROR: page name starts with dots and/or slashes, aborting' unless $quiet == true
|
100
101
|
return
|
101
102
|
end
|
102
103
|
|
103
104
|
# Read template
|
104
105
|
template_index = nil
|
105
106
|
template_meta = nil
|
107
|
+
template_content_filename = nil
|
106
108
|
template = a_params[:template] || 'default'
|
107
109
|
begin
|
108
|
-
template_meta = File.
|
109
|
-
|
110
|
-
|
110
|
+
template_meta = File.read("templates/#{template}/meta.yaml")
|
111
|
+
template_content_filenames = Dir.glob("templates/#{template}/#{template}.*")
|
112
|
+
template_content_filenames += Dir.glob("templates/#{template}/index.*")
|
113
|
+
template_content_filename = template_content_filenames[0]
|
114
|
+
template_index = File.read(template_content_filename)
|
111
115
|
rescue
|
112
|
-
$stderr.puts 'ERROR: no such template'
|
116
|
+
$stderr.puts 'ERROR: no such template' unless $quiet == true
|
113
117
|
exit
|
114
118
|
end
|
115
119
|
template_meta = template_meta.eruby
|
@@ -118,7 +122,7 @@ module Nanoc
|
|
118
122
|
# Create index and yaml file
|
119
123
|
FileManager.create_dir 'content' do
|
120
124
|
FileManager.create_dir a_pagename do
|
121
|
-
FileManager.create_file
|
125
|
+
FileManager.create_file "#{a_pagename}#{File.extname(template_content_filename)}" do
|
122
126
|
template_index
|
123
127
|
end
|
124
128
|
FileManager.create_file 'meta.yaml' do
|
@@ -130,10 +134,10 @@ module Nanoc
|
|
130
134
|
|
131
135
|
def self.create_template(a_templatename)
|
132
136
|
Nanoc.ensure_in_site
|
133
|
-
|
137
|
+
|
134
138
|
FileManager.create_dir 'templates' do
|
135
139
|
FileManager.create_dir a_templatename do
|
136
|
-
FileManager.create_file
|
140
|
+
FileManager.create_file "#{a_templatename}.txt" do
|
137
141
|
"This is a new page. Please edit me!\n"
|
138
142
|
end
|
139
143
|
FileManager.create_file 'meta.yaml' do
|
data/lib/enhancements.rb
CHANGED
@@ -11,26 +11,17 @@ require 'yaml'
|
|
11
11
|
class Array
|
12
12
|
# Ensures that the array contains only one element
|
13
13
|
def ensure_single(a_noun, a_context)
|
14
|
-
|
14
|
+
if self.size != 1
|
15
|
+
$stderr.puts "ERROR: expected 1 #{a_noun}, found #{self.size} (#{a_context})" unless $quiet == true
|
16
|
+
exit
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
|
-
|
19
|
-
# Reads the contents of the entire file
|
20
|
-
def self.read_file(a_filename)
|
21
|
-
content = ''
|
22
|
-
File.open(a_filename) { |io| content = io.read }
|
23
|
-
content
|
24
|
-
end
|
25
|
-
|
26
|
-
# Returns the contents of an entire file interpreted as YAML
|
27
|
-
def self.read_yaml(a_filename)
|
28
|
-
YAML::load(self.read_file(a_filename)) || {}
|
29
|
-
end
|
30
|
-
|
21
|
+
module YAML
|
31
22
|
# Returns the contents of an entire file interpreted as YAML and cleaned
|
32
|
-
def self.
|
33
|
-
|
23
|
+
def self.load_file_and_clean(a_filename)
|
24
|
+
(YAML.load_file(a_filename) || {}).clean
|
34
25
|
end
|
35
26
|
end
|
36
27
|
|
@@ -38,9 +29,7 @@ class Hash
|
|
38
29
|
# Converts all keys to symbols, and converts *_at and *_on
|
39
30
|
# keys to Times and Dates, respectively
|
40
31
|
def clean
|
41
|
-
hash
|
42
|
-
|
43
|
-
self.each_pair do |key, value|
|
32
|
+
inject({}) do |hash, (key, value)|
|
44
33
|
if key =~ /_on$/
|
45
34
|
hash[key.to_sym] = Date.parse(value)
|
46
35
|
elsif key =~ /_at$/
|
@@ -49,27 +38,28 @@ class Hash
|
|
49
38
|
hash[key.to_sym] = true
|
50
39
|
elsif value == 'false'
|
51
40
|
hash[key.to_sym] = false
|
41
|
+
elsif value == 'none'
|
42
|
+
hash[key.to_sym] = nil
|
52
43
|
else
|
53
44
|
hash[key.to_sym] = value
|
54
45
|
end
|
46
|
+
hash
|
55
47
|
end
|
56
|
-
|
57
|
-
hash
|
58
48
|
end
|
59
49
|
end
|
60
50
|
|
61
51
|
class String
|
62
52
|
# Runs the string through the filters as given by the array of
|
63
53
|
# filter names. Available filters include 'markdown', 'smartypants' and 'eruby'.
|
64
|
-
def filter
|
65
|
-
a_filters.
|
54
|
+
def filter(a_filters, a_params={})
|
55
|
+
a_filters.inject(self) do |result, filter|
|
66
56
|
case filter
|
67
57
|
when 'markdown'
|
68
|
-
|
58
|
+
result.replace(result.markdown)
|
69
59
|
when 'smartypants'
|
70
|
-
|
60
|
+
result.replace(result.smartypants)
|
71
61
|
when 'eruby'
|
72
|
-
|
62
|
+
result.replace(result.eruby(a_params[:eruby_context]))
|
73
63
|
end
|
74
64
|
end
|
75
65
|
end
|
@@ -78,7 +68,7 @@ class String
|
|
78
68
|
def markdown
|
79
69
|
BlueCloth::new(self).to_html
|
80
70
|
rescue NameError
|
81
|
-
$stderr.puts 'ERROR: String#markdown failed: BlueCloth not installed'
|
71
|
+
$stderr.puts 'ERROR: String#markdown failed: BlueCloth not installed' unless $quiet == true
|
82
72
|
exit
|
83
73
|
end
|
84
74
|
|
@@ -86,7 +76,7 @@ class String
|
|
86
76
|
def smartypants
|
87
77
|
RubyPants::new(self).to_html
|
88
78
|
rescue NameError
|
89
|
-
$stderr.puts 'ERROR: String#smartypants failed: RubyPants not installed'
|
79
|
+
$stderr.puts 'ERROR: String#smartypants failed: RubyPants not installed' unless $quiet == true
|
90
80
|
exit
|
91
81
|
end
|
92
82
|
|
@@ -99,25 +89,50 @@ end
|
|
99
89
|
class FileManager
|
100
90
|
@@stack = []
|
101
91
|
|
92
|
+
COLORS = {
|
93
|
+
:reset => "\e[0m",
|
94
|
+
|
95
|
+
:bold => "\e[1m",
|
96
|
+
|
97
|
+
:black => "\e[30m",
|
98
|
+
:red => "\e[31m",
|
99
|
+
:green => "\e[32m",
|
100
|
+
:yellow => "\e[33m",
|
101
|
+
:blue => "\e[34m",
|
102
|
+
:magenta => "\e[35m",
|
103
|
+
:cyan => "\e[36m",
|
104
|
+
:white => "\e[37m"
|
105
|
+
}
|
106
|
+
ACTION_COLORS = {
|
107
|
+
:create => COLORS[:bold] + COLORS[:green],
|
108
|
+
:update => COLORS[:bold] + COLORS[:yellow],
|
109
|
+
:identical => COLORS[:bold]
|
110
|
+
}
|
111
|
+
|
102
112
|
def self.create_dir(a_name)
|
103
113
|
@@stack.push(a_name)
|
104
|
-
|
105
|
-
|
106
|
-
FileUtils.mkdir_p(
|
114
|
+
path = File.join(@@stack)
|
115
|
+
unless File.directory?(path)
|
116
|
+
FileUtils.mkdir_p(path)
|
117
|
+
log('create', path)
|
107
118
|
end
|
108
119
|
yield if block_given?
|
109
120
|
@@stack.pop
|
110
121
|
end
|
111
122
|
|
112
123
|
def self.create_file(a_name)
|
113
|
-
path = @@stack.empty? ? a_name :
|
124
|
+
path = @@stack.empty? ? a_name : File.join(@@stack + [ a_name ])
|
114
125
|
FileManager.create_dir(path.sub(/\/[^\/]+$/, '')) if @@stack.empty?
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
else
|
119
|
-
open(path, 'w') { |io| }
|
120
|
-
end
|
126
|
+
content = block_given? ? yield : nil
|
127
|
+
File.exist?(path) ? ( block_given? and File.read(path) == content ? log('identical', path) : log('update', path) ) : log('create', path)
|
128
|
+
open(path, 'w') { |io| io.write(content) unless content.nil? }
|
121
129
|
end
|
122
130
|
|
131
|
+
def self.log(a_action, a_path)
|
132
|
+
puts format('%s%12s%s %s', ACTION_COLORS[a_action.to_sym], a_action, COLORS[:reset], a_path) unless $quiet == true
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def render(a_name, a_context={})
|
137
|
+
File.read('layouts/' + a_name + '.erb').eruby(a_context.merge({ :page => @page, :pages => @pages }))
|
123
138
|
end
|
data/lib/nanoc.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module Nanoc
|
2
|
-
VERSION = '1.
|
3
|
-
|
2
|
+
VERSION = '1.1'
|
3
|
+
|
4
4
|
def self.ensure_in_site
|
5
5
|
unless in_site?
|
6
6
|
$stderr.puts 'ERROR: The current working directory does not seem to be a valid/complete nanoc site directory; aborting.'
|
7
7
|
exit
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
private
|
12
|
-
|
12
|
+
|
13
13
|
def self.in_site?
|
14
14
|
return false unless File.directory?('content')
|
15
15
|
return false unless File.directory?('layouts')
|
@@ -17,11 +17,11 @@ module Nanoc
|
|
17
17
|
return false unless File.directory?('output')
|
18
18
|
return false unless File.directory?('tasks')
|
19
19
|
return false unless File.directory?('templates')
|
20
|
-
|
20
|
+
|
21
21
|
return false unless File.exist?('config.yaml')
|
22
22
|
return false unless File.exist?('meta.yaml')
|
23
23
|
return false unless File.exist?('Rakefile')
|
24
|
-
|
24
|
+
|
25
25
|
true
|
26
26
|
end
|
27
27
|
end
|
metadata
CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: nanoc
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2007-05-
|
8
|
-
summary: a CMS that doesn't
|
6
|
+
version: "1.1"
|
7
|
+
date: 2007-05-08 00:00:00 +02:00
|
8
|
+
summary: a CMS that doesn't run on your server
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: denis.defreyne@stoneship.org
|
12
12
|
homepage: http://stoneship.org/software/nanoc
|
13
13
|
rubyforge_project:
|
14
|
-
description: a CMS that doesn't
|
14
|
+
description: a CMS that doesn't run on your server
|
15
15
|
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
@@ -37,9 +37,6 @@ files:
|
|
37
37
|
- lib/creator.rb
|
38
38
|
- lib/enhancements.rb
|
39
39
|
- lib/nanoc.rb
|
40
|
-
- test/test_compile.rb
|
41
|
-
- test/test_create.rb
|
42
|
-
- test/test_enhancements.rb
|
43
40
|
test_files: []
|
44
41
|
|
45
42
|
rdoc_options: []
|
data/test/test_compile.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../lib/nanoc.rb'
|
4
|
-
|
5
|
-
class CompileTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
FileManager.create_dir 'tmp'
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
FileUtils.rm_rf 'tmp'
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_compile
|
15
|
-
FileUtils.cd('tmp')
|
16
|
-
Nanoc::Creator.create_site('site')
|
17
|
-
FileUtils.cd('site')
|
18
|
-
Nanoc::Creator.create_page('moo')
|
19
|
-
Nanoc::Compiler.new.run
|
20
|
-
FileUtils.cd('..')
|
21
|
-
FileUtils.cd('..')
|
22
|
-
|
23
|
-
assert File.file?('tmp/site/output/index.html')
|
24
|
-
assert File.file?('tmp/site/output/moo/index.html')
|
25
|
-
end
|
26
|
-
end
|
data/test/test_create.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../lib/nanoc.rb'
|
4
|
-
|
5
|
-
class CreateTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
FileManager.create_dir 'tmp'
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
FileUtils.rm_rf 'tmp'
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_create_site
|
15
|
-
FileUtils.cd('tmp')
|
16
|
-
Nanoc::Creator.create_site('site')
|
17
|
-
FileUtils.cd('..')
|
18
|
-
|
19
|
-
assert File.directory?('tmp/site/')
|
20
|
-
|
21
|
-
assert File.file?('tmp/site/config.yaml')
|
22
|
-
assert File.file?('tmp/site/meta.yaml')
|
23
|
-
assert File.file?('tmp/site/Rakefile')
|
24
|
-
|
25
|
-
assert File.directory?('tmp/site/content/')
|
26
|
-
assert File.file?('tmp/site/content/index.txt')
|
27
|
-
assert File.file?('tmp/site/content/meta.yaml')
|
28
|
-
|
29
|
-
assert File.directory?('tmp/site/layouts/')
|
30
|
-
assert File.file?('tmp/site/layouts/default.erb')
|
31
|
-
|
32
|
-
assert File.directory?('tmp/site/lib/')
|
33
|
-
assert File.file?('tmp/site/lib/default.rb')
|
34
|
-
|
35
|
-
assert File.directory?('tmp/site/output/')
|
36
|
-
|
37
|
-
assert File.directory?('tmp/site/templates/')
|
38
|
-
assert File.directory?('tmp/site/templates/default/')
|
39
|
-
assert File.file?('tmp/site/templates/default/index.txt')
|
40
|
-
assert File.file?('tmp/site/templates/default/meta.yaml')
|
41
|
-
|
42
|
-
assert File.directory?('tmp/site/tasks/')
|
43
|
-
assert File.file?('tmp/site/tasks/default.rake')
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_create_page
|
47
|
-
FileUtils.cd('tmp')
|
48
|
-
Nanoc::Creator.create_site('site')
|
49
|
-
FileUtils.cd('site')
|
50
|
-
Nanoc::Creator.create_page('moo')
|
51
|
-
FileUtils.cd('..')
|
52
|
-
FileUtils.cd('..')
|
53
|
-
|
54
|
-
assert File.directory?('tmp/site/content/moo/')
|
55
|
-
assert File.file?('tmp/site/content/moo/index.txt')
|
56
|
-
assert File.file?('tmp/site/content/moo/meta.yaml')
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_create_template
|
60
|
-
FileUtils.cd('tmp')
|
61
|
-
Nanoc::Creator.create_site('site')
|
62
|
-
FileUtils.cd('site')
|
63
|
-
Nanoc::Creator.create_template('moo')
|
64
|
-
FileUtils.cd('..')
|
65
|
-
FileUtils.cd('..')
|
66
|
-
|
67
|
-
assert File.directory?('tmp/site/templates/moo/')
|
68
|
-
assert File.file?('tmp/site/templates/moo/index.txt')
|
69
|
-
assert File.file?('tmp/site/templates/moo/meta.yaml')
|
70
|
-
end
|
71
|
-
end
|
data/test/test_enhancements.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
require File.dirname(__FILE__) + '/../lib/nanoc.rb'
|
6
|
-
|
7
|
-
class EnhancementsTest < Test::Unit::TestCase
|
8
|
-
def setup
|
9
|
-
open('test.yaml', 'w') do |io|
|
10
|
-
io.write('created_at: 12/07/04')
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown
|
15
|
-
FileUtils.rm('test.yaml')
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_array_ensure_single
|
19
|
-
assert_raise RuntimeError do
|
20
|
-
[ ].ensure_single('moofs', 'blargh')
|
21
|
-
end
|
22
|
-
assert_raise RuntimeError do
|
23
|
-
[ 1, 2 ].ensure_single('moofs', 'blargh')
|
24
|
-
end
|
25
|
-
assert_nothing_raised do
|
26
|
-
[ 1 ].ensure_single('moofs', 'blargh')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_file_read_file
|
31
|
-
assert_equal 'created_at: 12/07/04', File.read_file('test.yaml')
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_file_read_yaml
|
35
|
-
assert_equal({ 'created_at' => '12/07/04' }, File.read_yaml('test.yaml'))
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_file_read_clean_yaml
|
39
|
-
assert_equal({ :created_at => Time.parse('12/07/04') }, File.read_clean_yaml('test.yaml'))
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_hash_clean
|
43
|
-
hash1 = { 'foo' => 'bar' }
|
44
|
-
hash1_cleaned = { :foo => 'bar' }
|
45
|
-
|
46
|
-
hash2 = { 'created_at' => '12/07/2004' }
|
47
|
-
hash2_cleaned = { :created_at => Time.parse('12/07/2004') }
|
48
|
-
|
49
|
-
assert_equal hash1_cleaned, hash1.clean
|
50
|
-
assert_equal hash2_cleaned, hash2.clean
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_string_filter!
|
54
|
-
text = '<%= @foo %>'
|
55
|
-
context = { :foo => 'Te\'st' }
|
56
|
-
|
57
|
-
text.filter!([ 'eruby' ], :eruby_context => context)
|
58
|
-
assert_equal 'Te\'st', text
|
59
|
-
|
60
|
-
begin
|
61
|
-
text.filter!([ 'markdown', 'smartypants' ])
|
62
|
-
assert_equal '<p>Te’st</p>', text
|
63
|
-
rescue NameError
|
64
|
-
$stderr.puts 'WARNING: Unable to test String#filter! (BlueCloth or RubyPants not installed)'
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_string_markdown
|
69
|
-
begin
|
70
|
-
assert_equal 'Hello!'.markdown, '<p>Hello!</p>'
|
71
|
-
rescue NameError
|
72
|
-
$stderr.puts 'WARNING: Unable to test String#markdown (BlueCloth not installed)'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_string_smartypants
|
77
|
-
begin
|
78
|
-
assert_equal 'Te\'st'.smartypants, 'Te’st'
|
79
|
-
rescue NameError
|
80
|
-
$stderr.puts 'WARNING: Unable to test String#smartypants (RubyPants not installed)'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_string_eruby
|
85
|
-
assert_equal '<%= "moo" %>'.eruby, 'moo'
|
86
|
-
assert_equal '<%= @foo %>'.eruby(:foo => 'bar'), 'bar'
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_filemanager_create_dir
|
90
|
-
FileManager.create_dir 'tmp' do
|
91
|
-
FileManager.create_dir 'foo'
|
92
|
-
end
|
93
|
-
|
94
|
-
assert File.exist?('tmp')
|
95
|
-
assert File.directory?('tmp')
|
96
|
-
|
97
|
-
assert File.exist?('tmp/foo')
|
98
|
-
assert File.directory?('tmp/foo')
|
99
|
-
|
100
|
-
assert !File.exist?('foo')
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_filemanager_create_file
|
104
|
-
FileManager.create_dir 'tmp' do
|
105
|
-
FileManager.create_file 'bar' do
|
106
|
-
"asdf"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
assert File.exist?('tmp/bar')
|
111
|
-
assert File.file?('tmp/bar')
|
112
|
-
assert_equal 'asdf', File.read_file('tmp/bar')
|
113
|
-
end
|
114
|
-
end
|