hydeweb 0.0.8.pre2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGELOG → HISTORY.md} +6 -0
- data/Rakefile +2 -52
- data/bin/hyde +3 -23
- data/bin/hyde01 +7 -0
- data/data/new_site/README.md +1 -1
- data/data/new_site/hyde.conf +9 -6
- data/lib/hyde/cli/helpers.rb +40 -0
- data/lib/hyde/cli.rb +86 -0
- data/lib/hyde/config.rb +37 -0
- data/lib/hyde/helpers.rb +6 -47
- data/lib/hyde/layout.rb +17 -9
- data/lib/hyde/meta.rb +5 -21
- data/lib/hyde/page.rb +207 -159
- data/lib/hyde/partial.rb +10 -5
- data/lib/hyde/project.rb +58 -208
- data/lib/hyde/server.rb +57 -0
- data/lib/hyde.rb +28 -51
- data/test/fixture/extensions/extensions/a/a.rb +1 -0
- data/test/fixture/extensions/hyde.conf +8 -0
- data/test/fixture/extensions/site/index.haml +1 -0
- data/test/fixture/fail_type/control/about/index.html +2 -0
- data/test/fixture/fail_type/control/about/us.html +2 -0
- data/test/fixture/fail_type/control/index.html +1 -0
- data/test/fixture/fail_type/hyde.conf +8 -0
- data/test/fixture/fail_type/site/index.haml +4 -0
- data/test/fixture/nested_layout/control/index.html +2 -0
- data/test/fixture/nested_layout/hyde.conf +8 -0
- data/test/fixture/nested_layout/layouts/default.haml +2 -0
- data/test/{fixtures/content_for/site/default.html.haml → fixture/nested_layout/layouts/post.haml} +1 -0
- data/test/fixture/nested_layout/site/index.haml +4 -0
- data/test/fixture/one/control/about/index.css +2 -0
- data/test/fixture/one/control/cheers.html +5 -0
- data/test/fixture/one/control/css/style.css +2 -0
- data/test/fixture/one/control/hello.html +5 -0
- data/test/fixture/one/control/hi.html +1 -0
- data/test/fixture/one/control/index.html +7 -0
- data/test/fixture/one/hyde.conf +9 -0
- data/test/fixture/one/layouts/default.haml +4 -0
- data/test/fixture/one/partials/menu.haml +3 -0
- data/test/fixture/one/site/about/index.scss +1 -0
- data/test/fixture/one/site/cheers.html.haml +1 -0
- data/test/fixture/one/site/css/style.scss +2 -0
- data/test/fixture/one/site/hello.haml +1 -0
- data/test/fixture/one/site/hi.html +1 -0
- data/test/fixture/one/site/index.haml +7 -0
- data/test/fixture/parent/control/about/index.html +2 -0
- data/test/fixture/parent/control/about/us.html +2 -0
- data/test/fixture/parent/control/index.html +1 -0
- data/test/fixture/parent/hyde.conf +8 -0
- data/test/fixture/parent/site/about/index.haml +3 -0
- data/test/fixture/parent/site/about/us.haml +3 -0
- data/test/fixture/parent/site/index.haml +3 -0
- data/test/fixture/sort/hyde.conf +8 -0
- data/test/fixture/sort/site/about/hardy.haml +4 -0
- data/test/fixture/sort/site/about/intrepid.haml +4 -0
- data/test/fixture/sort/site/about.haml +3 -0
- data/test/fixture/subclass/control/index.html +1 -0
- data/test/fixture/subclass/extensions/a/a.rb +12 -0
- data/test/fixture/subclass/hyde.conf +8 -0
- data/test/fixture/subclass/layouts/default.haml +1 -0
- data/test/fixture/subclass/layouts/post.haml +1 -0
- data/test/fixture/subclass/site/index.haml +4 -0
- data/test/helper.rb +15 -21
- data/test/unit/extensions_test.rb +16 -0
- data/test/unit/fixture_test.rb +77 -0
- data/test/unit/hyde_test.rb +30 -0
- metadata +107 -153
- data/.yardopts +0 -5
- data/LICENSE +0 -20
- data/VERSION +0 -1
- data/data/new_site/.gitignore +0 -24
- data/data/pages/404.html +0 -3
- data/hydeweb.gemspec +0 -159
- data/lib/hyde/clicommand.rb +0 -60
- data/lib/hyde/clicommands.rb +0 -128
- data/lib/hyde/ostruct.rb +0 -13
- data/lib/hyde/page_factory.rb +0 -90
- data/lib/hyde/renderer.rb +0 -133
- data/lib/hyde/renderers.rb +0 -100
- data/lib/hyde/sinatra/init.rb +0 -64
- data/lib/hyde/utils.rb +0 -43
- data/lib/hyde_misc/console.rb +0 -4
- data/manual/Extending/ExtendingHyde.md +0 -118
- data/manual/Hyde.md +0 -63
- data/manual/Introduction/Configuration.md +0 -70
- data/manual/Introduction/GettingStarted.md +0 -64
- data/manual/Introduction/Installation.md +0 -16
- data/manual/Introduction/Layouts.md +0 -14
- data/manual/Introduction/Metadata.md +0 -94
- data/manual/Introduction/Partials.md +0 -73
- data/manual/Introduction/TemplateLanguages.md +0 -59
- data/manual/Tips/Tips.md +0 -42
- data/test/fixtures/content_for/_config.yml +0 -8
- data/test/fixtures/content_for/layouts/cf-args.haml +0 -2
- data/test/fixtures/content_for/layouts/cf.haml +0 -14
- data/test/fixtures/content_for/layouts/default.haml +0 -4
- data/test/fixtures/content_for/layouts/shared/test.haml +0 -4
- data/test/fixtures/content_for/site/cf-args-default.haml +0 -2
- data/test/fixtures/content_for/site/cf-args.haml +0 -5
- data/test/fixtures/content_for/site/cf.haml +0 -6
- data/test/fixtures/content_for/site/cf2.haml +0 -3
- data/test/fixtures/content_for/site/index.html.haml +0 -9
- data/test/fixtures/content_for/site/var.html.haml +0 -5
- data/test/fixtures/content_for/www_control/cf-args-default.html +0 -1
- data/test/fixtures/content_for/www_control/cf-args.html +0 -2
- data/test/fixtures/content_for/www_control/cf.html +0 -17
- data/test/fixtures/content_for/www_control/cf2.html +0 -19
- data/test/fixtures/content_for/www_control/default.html +0 -2
- data/test/fixtures/content_for/www_control/index.html +0 -10
- data/test/fixtures/content_for/www_control/var.html +0 -2
- data/test/fixtures/custom/_config.yml +0 -8
- data/test/fixtures/custom/extensions/custom/custom.rb +0 -9
- data/test/fixtures/custom/layouts/default.haml +0 -8
- data/test/fixtures/custom/layouts/erbtest.erb +0 -2
- data/test/fixtures/custom/layouts/shared/sidebar.haml +0 -4
- data/test/fixtures/custom/site/about/index.html +0 -1
- data/test/fixtures/custom/site/assets/common.css.less +0 -1
- data/test/fixtures/custom/site/assets/style.css.less +0 -3
- data/test/fixtures/custom/site/foo.html.haml +0 -3
- data/test/fixtures/custom/site/index.html.haml +0 -6
- data/test/fixtures/custom/site/layout_test.html.haml +0 -6
- data/test/fixtures/custom/site/lol.html.erb +0 -7
- data/test/fixtures/custom/site/markdown.html.md +0 -8
- data/test/fixtures/custom/site/yes.html +0 -2
- data/test/fixtures/custom/www_control/about/index.html +0 -1
- data/test/fixtures/custom/www_control/assets/common.css +0 -1
- data/test/fixtures/custom/www_control/assets/style.css +0 -6
- data/test/fixtures/custom/www_control/foo.html +0 -1
- data/test/fixtures/custom/www_control/index.html +0 -16
- data/test/fixtures/custom/www_control/layout_test.html +0 -16
- data/test/fixtures/custom/www_control/lol.html +0 -5
- data/test/fixtures/custom/www_control/markdown.html +0 -17
- data/test/fixtures/custom/www_control/yes.html +0 -2
- data/test/fixtures/default/_config.yml +0 -8
- data/test/fixtures/default/extensions/custom/custom.rb +0 -2
- data/test/fixtures/default/layouts/default.haml +0 -5
- data/test/fixtures/default/site/about/index.html +0 -1
- data/test/fixtures/default/site/foo.html.haml +0 -3
- data/test/fixtures/default/site/index.html.haml +0 -6
- data/test/fixtures/default/site/layout_test.html.haml +0 -6
- data/test/fixtures/default/site/yes.html +0 -2
- data/test/fixtures/default/www_control/about/index.html +0 -1
- data/test/fixtures/default/www_control/foo.html +0 -1
- data/test/fixtures/default/www_control/index.html +0 -9
- data/test/fixtures/default/www_control/layout_test.html +0 -9
- data/test/fixtures/default/www_control/yes.html +0 -2
- data/test/test_all_fixtures.rb +0 -51
- data/test/test_build.rb +0 -20
- data/test/test_hyde.rb +0 -75
- data/test/test_page.rb +0 -26
- data/test/test_utils.rb +0 -22
data/lib/hyde/page.rb
CHANGED
@@ -1,209 +1,257 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
class Hyde
|
2
|
+
class Page
|
3
|
+
attr_reader :project
|
4
|
+
attr_reader :file
|
5
|
+
|
6
|
+
# Returns the URL path for a page.
|
7
|
+
def path
|
8
|
+
path = @file.sub(root_path, '')
|
9
|
+
|
10
|
+
# if xx.haml (but not xx.html.haml),
|
11
|
+
if tilt?
|
12
|
+
path = path.sub(/\.[^\.]*$/, "")
|
13
|
+
path += ".#{default_ext}" unless File.basename(path).include?('.')
|
14
|
+
end
|
4
15
|
|
5
|
-
|
16
|
+
path
|
17
|
+
end
|
6
18
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# puts page.name
|
11
|
-
# puts page.filename
|
12
|
-
#
|
13
|
-
# # about/index.html
|
14
|
-
# # about/index.html.haml
|
15
|
-
#
|
16
|
-
attr_accessor :filename
|
19
|
+
def title
|
20
|
+
(meta.title if tilt?) || path
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
attr_accessor :meta
|
23
|
+
alias to_s title
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
def <=>(other)
|
26
|
+
result = self.position <=> other.position
|
27
|
+
result ||= self.position.to_s <=> other.position.to_s
|
28
|
+
result
|
29
|
+
end
|
24
30
|
|
25
|
-
|
26
|
-
|
31
|
+
def html?
|
32
|
+
mime_type == 'text/html'
|
33
|
+
end
|
27
34
|
|
28
|
-
|
35
|
+
def mime_type
|
36
|
+
return nil unless tilt?
|
29
37
|
|
30
|
-
|
38
|
+
mime = nil
|
39
|
+
mime = tilt_engine.default_mime_type if tilt_engine.respond_to?(:default_mime_type)
|
31
40
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
41
|
+
mime ||= case tilt_engine.name
|
42
|
+
when 'Tilt::SassTemplate' then 'text/css'
|
43
|
+
when 'Tilt::ScssTemplate' then 'text/css'
|
44
|
+
when 'Tilt::LessTemplate' then 'text/css'
|
45
|
+
when 'Tilt::CoffeeScriptTemplate' then 'application/javascript'
|
46
|
+
when 'Tilt::NokogiriTemplate' then 'text/xml'
|
47
|
+
when 'Tilt::BuilderTemplate' then 'text/xml'
|
48
|
+
else 'text/html'
|
36
49
|
end
|
50
|
+
end
|
37
51
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
52
|
+
def default_ext
|
53
|
+
case mime_type
|
54
|
+
when 'text/html' then 'html'
|
55
|
+
when 'text/css' then 'css'
|
56
|
+
when 'text/xml' then 'xml'
|
57
|
+
when 'application/javascript' then 'js'
|
43
58
|
end
|
59
|
+
end
|
44
60
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
61
|
+
def self.[](id, project=$project)
|
62
|
+
site = lambda { |*x| File.join root_path(project), *(x.compact) }
|
63
|
+
try = lambda { |id| p = new(id, project); p if p.exists? }
|
49
64
|
|
50
|
-
|
51
|
-
|
65
|
+
# Account for:
|
66
|
+
# ~/mysite/site/about/us.html.haml
|
67
|
+
# about/us.html.haml => ~/mysite/site/about/us.html.haml
|
68
|
+
# about/us.html => ~/mysite/site/about/us.html.*
|
69
|
+
# about/us.html => ~/mysite/site/about/us.*
|
70
|
+
# about/us => ~/mysite/site/about/us/index.*
|
71
|
+
#
|
72
|
+
page = try[id]
|
73
|
+
page ||= try[site[id]]
|
74
|
+
page ||= try[Dir[site["#{id}.*"]].first]
|
75
|
+
page ||= try[Dir[site["#{id.to_s.sub(/\.[^\.]*/,'')}.*"]].first]
|
76
|
+
page ||= try[Dir[site[id, "index.*"]].first]
|
77
|
+
|
78
|
+
# Subclass
|
79
|
+
if page && page.tilt? && page.meta.type
|
80
|
+
klass = Page.get_type(page.meta.type)
|
81
|
+
raise Error, "Class for type '#{page.meta.type}' not found" unless klass
|
82
|
+
page = klass.new(id, project)
|
52
83
|
end
|
84
|
+
page
|
85
|
+
end
|
53
86
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
87
|
+
# Returns a page subtype.
|
88
|
+
# @example Page.get_type('post') => Hyde::Page::Post
|
89
|
+
def self.get_type(type)
|
90
|
+
klass = type[0].upcase + type[1..-1].downcase
|
91
|
+
klass = klass.to_sym
|
92
|
+
self.const_get(klass) if self.const_defined?(klass)
|
93
|
+
end
|
62
94
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
else
|
69
|
-
File.basename(filename, '.*')
|
70
|
-
end
|
71
|
-
end
|
95
|
+
def initialize(file, project=$project)
|
96
|
+
@file = file
|
97
|
+
@project = project
|
98
|
+
raise Error if project.nil?
|
99
|
+
end
|
72
100
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
if renderer.is_a?(Renderer::Passthru)
|
77
|
-
'/' + @name
|
78
|
-
else
|
79
|
-
url = [ File.dirname(@name), File.basename(@filename) ]
|
80
|
-
url[1] = File.basename(url[1], '.*')
|
81
|
-
url[1] = (url[1] + @renderer.default_ext) unless url[1].include?('.')
|
82
|
-
'/' + url.join('/')
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
101
|
+
def exists?
|
102
|
+
@file and File.file?(@file) and valid?
|
103
|
+
end
|
86
104
|
|
87
|
-
|
88
|
-
|
89
|
-
|
105
|
+
# Make sure that it's in the right folder.
|
106
|
+
def valid?
|
107
|
+
prefix = File.expand_path(root_path)
|
108
|
+
prefix == File.expand_path(@file)[0...prefix.size]
|
109
|
+
end
|
90
110
|
|
91
|
-
|
92
|
-
|
93
|
-
|
111
|
+
def content(locals={}, &blk)
|
112
|
+
return markup unless tilt?
|
113
|
+
# Build scope
|
114
|
+
scope = self.dup
|
115
|
+
scope.extend Helpers
|
116
|
+
scope.meta.merge! locals
|
94
117
|
|
95
|
-
|
96
|
-
|
97
|
-
end
|
118
|
+
tilt.render(scope, &blk)
|
119
|
+
end
|
98
120
|
|
99
|
-
|
100
|
-
|
101
|
-
|
121
|
+
def to_html(locals={}, &blk)
|
122
|
+
html = content(locals, &blk)
|
123
|
+
html = layout.to_html(locals) { html } if layout?
|
124
|
+
html
|
125
|
+
end
|
102
126
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
127
|
+
def layout
|
128
|
+
layout = meta.layout
|
129
|
+
layout ||= default_layout unless meta.layout == false
|
130
|
+
Layout[layout, page] if layout
|
131
|
+
end
|
108
132
|
|
109
|
-
|
110
|
-
|
111
|
-
|
133
|
+
def page
|
134
|
+
self
|
135
|
+
end
|
112
136
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
folder = File.expand_path(folder)
|
137
|
+
def layout?
|
138
|
+
!! layout
|
139
|
+
end
|
117
140
|
|
118
|
-
|
119
|
-
|
141
|
+
def meta
|
142
|
+
@meta ||= Meta.new(YAML::load(parts.first))
|
143
|
+
end
|
120
144
|
|
121
|
-
|
122
|
-
|
145
|
+
# Writes to the given output file.
|
146
|
+
def write(out=nil)
|
147
|
+
out ||= project.path(:output, path)
|
148
|
+
FileUtils.mkdir_p File.dirname(out)
|
123
149
|
|
124
|
-
|
150
|
+
if tilt?
|
151
|
+
File.open(out, 'w') { |f| f.write to_html }
|
152
|
+
else
|
153
|
+
FileUtils.cp file, out
|
125
154
|
end
|
155
|
+
end
|
126
156
|
|
127
|
-
|
128
|
-
|
129
|
-
|
157
|
+
# Checks if the file is supported by tilt.
|
158
|
+
def tilt?
|
159
|
+
!! tilt_engine
|
160
|
+
end
|
130
161
|
|
131
|
-
|
132
|
-
|
162
|
+
# Returns the Tilt engine (eg Tilt::HamlEngine).
|
163
|
+
def tilt_engine
|
164
|
+
Tilt[@file]
|
165
|
+
end
|
133
166
|
|
134
|
-
|
135
|
-
|
136
|
-
|
167
|
+
def tilt_engine_name
|
168
|
+
tilt_engine.name.match(/:([^:]*)(?:Template?)$/)[1]
|
169
|
+
end
|
137
170
|
|
138
|
-
|
171
|
+
# Returns the tilt layout.
|
172
|
+
def tilt
|
173
|
+
if tilt?
|
174
|
+
begin
|
175
|
+
# HAML options and such (like :escape_html)
|
176
|
+
options = project.config.tilt_options_for(@file)
|
177
|
+
offset = parts.first.count("\n") + 2
|
178
|
+
@tilt ||= Tilt.new(@file, offset, options) { markup }
|
179
|
+
rescue LoadError => e
|
180
|
+
gem = e.message.split(' ').last
|
181
|
+
ext = File.extname(@file)
|
182
|
+
raise NoGemError, "You need the '#{gem}' gem to parse #{ext} files."
|
183
|
+
end
|
139
184
|
end
|
185
|
+
end
|
140
186
|
|
141
|
-
|
142
|
-
|
143
|
-
|
187
|
+
def markup
|
188
|
+
parts.last
|
189
|
+
end
|
144
190
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
a << PageFactory.create(name, @project) unless name.nil?
|
191
|
+
def method_missing(meth, *args, &blk)
|
192
|
+
super unless meta.instance_variable_get(:@table).keys.include?(meth.to_sym)
|
193
|
+
meta.send(meth)
|
194
|
+
end
|
150
195
|
|
151
|
-
|
152
|
-
|
153
|
-
|
196
|
+
def parent
|
197
|
+
parts = path.split('/')
|
198
|
+
parent_path = index? ? parts[0...-2] : parts[0...-1]
|
199
|
+
self.class[parent_path.join('/'), project]
|
200
|
+
end
|
154
201
|
|
155
|
-
|
156
|
-
|
157
|
-
|
202
|
+
def children
|
203
|
+
files = if index?
|
204
|
+
# about/index.html => about/*
|
205
|
+
File.expand_path('../*', @file)
|
206
|
+
else
|
207
|
+
# products.html => products/*
|
208
|
+
base = File.basename(@file, '.*')
|
209
|
+
File.expand_path("../#{base}/*", @file)
|
158
210
|
end
|
159
211
|
|
160
|
-
|
161
|
-
|
162
|
-
@crumbs ||= parent.nil? ? [] : (parent.breadcrumbs + [parent])
|
163
|
-
end
|
212
|
+
Dir[files].reject { |f| f == @file }.map { |f| self.class[f, project] }.compact.sort
|
213
|
+
end
|
164
214
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
215
|
+
def siblings
|
216
|
+
p = parent and p.children
|
217
|
+
end
|
169
218
|
|
170
|
-
|
171
|
-
|
172
|
-
|
219
|
+
def breadcrumbs
|
220
|
+
parent? ? (parent.breadcrumbs + [self]) : [self]
|
221
|
+
end
|
222
|
+
|
223
|
+
def index?
|
224
|
+
File.basename(path, '.*') == 'index'
|
225
|
+
end
|
173
226
|
|
174
|
-
|
175
|
-
|
176
|
-
|
227
|
+
def parent?
|
228
|
+
!parent.nil?
|
229
|
+
end
|
177
230
|
|
178
|
-
|
179
|
-
|
180
|
-
|
231
|
+
def root?
|
232
|
+
parent.nil?
|
233
|
+
end
|
181
234
|
|
182
|
-
|
235
|
+
protected
|
236
|
+
def default_layout
|
237
|
+
'default' if html?
|
238
|
+
end
|
183
239
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
@name ||= path
|
191
|
-
@meta ||= Meta.new self
|
192
|
-
@filename = filename
|
193
|
-
@renderer = renderer.new(self, filename)
|
194
|
-
end
|
195
|
-
|
196
|
-
def self.get_filename(path, project)
|
197
|
-
project.root(:site, path)
|
240
|
+
# Returns the two parts of the markup.
|
241
|
+
def parts
|
242
|
+
@parts ||= begin
|
243
|
+
t = File.open(@file).read.force_encoding('UTF-8')
|
244
|
+
m = t.match(/^(.*)--+\n(.*)$/m)
|
245
|
+
m.nil? ? ['', t] : [m[1], m[2]]
|
198
246
|
end
|
247
|
+
end
|
199
248
|
|
200
|
-
|
249
|
+
def self.root_path(project, *a)
|
250
|
+
project.path(:site, *a)
|
251
|
+
end
|
201
252
|
|
202
|
-
|
203
|
-
|
204
|
-
data = @meta | data
|
205
|
-
data[:page] ||= self
|
206
|
-
data
|
207
|
-
end
|
253
|
+
def root_path(*a)
|
254
|
+
self.class.root_path(project, *a)
|
208
255
|
end
|
209
256
|
end
|
257
|
+
end
|
data/lib/hyde/partial.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
class Hyde
|
2
|
+
class Partial < Layout
|
3
|
+
protected
|
4
|
+
def self.root_path(project, *a)
|
5
|
+
project.path(:partials, *a)
|
6
6
|
end
|
7
|
+
|
8
|
+
def default_layout
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
end
|
7
12
|
end
|