hydeweb 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +7 -0
- data/lib/hyde/cli/helpers.rb +18 -0
- data/lib/hyde/cli.rb +52 -18
- data/lib/hyde/page.rb +5 -11
- data/lib/hyde.rb +1 -2
- metadata +1 -1
data/HISTORY.md
CHANGED
data/lib/hyde/cli/helpers.rb
CHANGED
@@ -27,12 +27,22 @@ module Helpers
|
|
27
27
|
say_status '*', str, 30
|
28
28
|
end
|
29
29
|
|
30
|
+
def say_error(str)
|
31
|
+
say_status 'error', str, 31
|
32
|
+
end
|
33
|
+
|
30
34
|
def say_status(what, cmd, color=32)
|
31
35
|
c1 = "\033[0;#{color}m"
|
32
36
|
c0 = "\033[0;m"
|
33
37
|
puts "#{c1}%10s#{c0} %s" % [ what, cmd ]
|
34
38
|
end
|
35
39
|
|
40
|
+
def show_needed_gem(name)
|
41
|
+
err
|
42
|
+
say_error "You will need additional gems for this project."
|
43
|
+
say_info "To install: gem install #{name}"
|
44
|
+
end
|
45
|
+
|
36
46
|
def no_project
|
37
47
|
"Error: no Hyde config file found.\n" +
|
38
48
|
"(Looked for #{Hyde::CONFIG_FILES.join(', ')})\n\n" +
|
@@ -46,6 +56,14 @@ module Helpers
|
|
46
56
|
!! @hydefile
|
47
57
|
end
|
48
58
|
|
59
|
+
# Gets the gem name from a LoadError exception.
|
60
|
+
def gem_name(e)
|
61
|
+
name = e.message.split(' ').last
|
62
|
+
name = 'RedCloth' if name == 'redcloth'
|
63
|
+
name = 'haml' if name == 'sass/plugin'
|
64
|
+
name
|
65
|
+
end
|
66
|
+
|
49
67
|
def project
|
50
68
|
@project ||= begin
|
51
69
|
pass no_project unless project?
|
data/lib/hyde/cli.rb
CHANGED
@@ -47,19 +47,16 @@ class CLI < Shake
|
|
47
47
|
task(:build) do
|
48
48
|
pre = project.config.output_path
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
ensure
|
61
|
-
project.send :build_cleanup
|
62
|
-
end
|
50
|
+
project.build { |page|
|
51
|
+
c, handler = if page.tilt?
|
52
|
+
[ 33, "#{page.tilt_engine_name.downcase}" ]
|
53
|
+
else
|
54
|
+
[ 30, '*' ]
|
55
|
+
end
|
56
|
+
|
57
|
+
puts ("\033[0;#{c}m%10s\033[0;32m #{pre}\033[0;m%s" % [ handler, page.path ]).strip
|
58
|
+
}
|
59
|
+
project.send :build_cleanup
|
63
60
|
end
|
64
61
|
|
65
62
|
task.description = "Builds the current project"
|
@@ -151,14 +148,51 @@ class CLI < Shake
|
|
151
148
|
end
|
152
149
|
end
|
153
150
|
|
154
|
-
def self.run
|
155
|
-
|
156
|
-
|
157
|
-
|
151
|
+
def self.run(*argv)
|
152
|
+
return invoke(:version) if argv == ['-v'] || argv == ['--version']
|
153
|
+
trace = (!!argv.delete('--trace'))
|
154
|
+
|
158
155
|
|
159
156
|
begin
|
160
|
-
super *
|
157
|
+
super *argv
|
158
|
+
|
159
|
+
rescue SyntaxError => e
|
160
|
+
raise e if trace
|
161
|
+
err
|
162
|
+
say_error e.message.split("\n").last
|
163
|
+
err
|
164
|
+
say_error "You have a syntax error."
|
165
|
+
say_info "Use --trace for more info."
|
166
|
+
|
167
|
+
# Convert 'can't load redcloth' to a friendly 'please gem install RedCloth'
|
168
|
+
rescue LoadError => e
|
169
|
+
raise e if trace
|
170
|
+
show_needed_gem gem_name(e)
|
171
|
+
|
172
|
+
# Print generic errors as something friendlier
|
173
|
+
rescue => e
|
174
|
+
raise e if trace
|
175
|
+
|
176
|
+
# Can't assume that HAML is always available.
|
177
|
+
if Object.const_defined?(:Haml) && e.is_a?(Haml::Error)
|
178
|
+
# Convert HAML's "Can't run XX filter; required 'yy'" messages
|
179
|
+
# to something friendlier
|
180
|
+
needed = %w(rdiscount stringio sass/plugin redcloth)
|
181
|
+
needed.detect { |what| show_needed_gem(what) && true if e.message.include?(what) }
|
182
|
+
else
|
183
|
+
err
|
184
|
+
say_error "#{e.class}: #{e.message}"
|
185
|
+
say_info "#{e.backtrace.first}"
|
186
|
+
err
|
187
|
+
say_error "Oops! An error occured."
|
188
|
+
say_info "Use --trace for more info."
|
189
|
+
end
|
161
190
|
end
|
162
191
|
end
|
192
|
+
|
193
|
+
def self.run!(options={})
|
194
|
+
@hydefile = options[:file]
|
195
|
+
super *[]
|
196
|
+
end
|
163
197
|
end
|
164
198
|
end
|
data/lib/hyde/page.rb
CHANGED
@@ -188,17 +188,11 @@ class Page
|
|
188
188
|
# Returns the tilt layout.
|
189
189
|
def tilt
|
190
190
|
if tilt?
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
@tilt ||= Tilt.new(@file, offset, options) { markup }
|
197
|
-
rescue LoadError => e
|
198
|
-
gem = e.message.split(' ').last
|
199
|
-
ext = File.extname(@file)
|
200
|
-
raise NoGemError, "You need the '#{gem}' gem to parse #{ext} files."
|
201
|
-
end
|
191
|
+
parts
|
192
|
+
# HAML options and such (like :escape_html)
|
193
|
+
options = project.config.tilt_options_for(@file)
|
194
|
+
offset = @offset || 1
|
195
|
+
@tilt ||= Tilt.new(@file, offset, options) { markup }
|
202
196
|
end
|
203
197
|
end
|
204
198
|
|
data/lib/hyde.rb
CHANGED
@@ -15,13 +15,12 @@ require 'shake'
|
|
15
15
|
Tilt.mappings['html'] = Tilt.mappings['erb']
|
16
16
|
|
17
17
|
class Hyde
|
18
|
-
VERSION = "0.1.
|
18
|
+
VERSION = "0.1.7"
|
19
19
|
PREFIX = File.expand_path('../', __FILE__)
|
20
20
|
|
21
21
|
Error = Class.new(StandardError)
|
22
22
|
LegacyError = Class.new(Error)
|
23
23
|
VersionError = Class.new(Error)
|
24
|
-
NoGemError = Class.new(Error)
|
25
24
|
|
26
25
|
# Allowed config filenames
|
27
26
|
CONFIG_FILES = ['hyde.conf', '.hyderc']
|