hydeweb 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,13 @@
1
+ v0.1.8
2
+ ------
3
+
4
+ - Fix: 404 pages in 'hyde start' no longer throws an exception log to the viewer.
5
+ - Implemented the `content_for` and `yield_content` helpers.
6
+ - Fix partial locals not working.
7
+ - Allow having the same layouts/partials path as the site.
8
+ - Implement `Hyde.project` which returns the latest project. (deprecates $project)
9
+ - Support tilt_build_options in the config.
10
+
1
11
  v0.1.7
2
12
  ------
3
13
 
data/TODO.md ADDED
@@ -0,0 +1,3 @@
1
+ - Post build hooks?
2
+ - tilt_build_options
3
+ - deprecate $project, implement Hyde.project
@@ -25,4 +25,11 @@ tilt_options:
25
25
  :escape_html: true
26
26
  scss:
27
27
  :load_paths: [ 'css' ]
28
+ :style: :compact
29
+ :line_numbers: true
28
30
 
31
+ # Optional settings for doing a build
32
+ tilt_build_options:
33
+ scss:
34
+ :style: :compressed
35
+ :line_numbers: false
data/lib/hyde/config.rb CHANGED
@@ -20,22 +20,25 @@ class Config < OpenStruct
20
20
 
21
21
  # Returns tilt options for a given file.
22
22
  # @example tilt_options('index.haml') # { :escape_html => ... }
23
- def tilt_options_for(file)
24
- tilt_options file.split('.').last.downcase
23
+ def tilt_options_for(file, options)
24
+ ext = file.split('.').last.downcase
25
+ opts = tilt_options(ext)
26
+ opts = opts.merge(tilt_options(ext, :tilt_build_options)) if options[:build]
27
+ opts
25
28
  end
26
29
 
27
30
  # Returns tilt options for a given engine.
28
31
  # @example tilt_options('haml') # { :escape_html => ... }
29
- def tilt_options(what)
30
- @tilt_options ||= begin
31
- o = @table[:tilt_options] || Hash.new
32
- o['haml'] ||= { :escape_html => true }
33
- o['scss'] ||= { :load_path => ['css'] }
34
- o['sass'] ||= { :load_path => ['css'] }
35
- o
32
+ def tilt_options(what, key=:tilt_options)
33
+ @table[key] ||= begin
34
+ h = Hash.new { |h, k| h[k] = Hash.new }
35
+ h['haml'] = { :escape_html => true }
36
+ h['scss'] = { :load_path => ['css'] }
37
+ h['sass'] = { :load_path => ['css'] }
38
+ h
36
39
  end
37
40
 
38
- @tilt_options[what.to_s]
41
+ @table[key][what.to_s]
39
42
  end
40
43
  end
41
44
  end
data/lib/hyde/helpers.rb CHANGED
@@ -2,7 +2,7 @@ class Hyde
2
2
  module Helpers
3
3
  def partial(path, locals={})
4
4
  partial = Partial[path.to_s, page] or return ''
5
- partial.to_html :page => self
5
+ partial.to_html locals.merge(:page => self)
6
6
  end
7
7
 
8
8
  def rel(path)
@@ -10,5 +10,27 @@ module Helpers
10
10
  dotdot = depth > 1 ? ('../' * (page.depth-1)) : './'
11
11
  (dotdot[0...-1] + path)
12
12
  end
13
+
14
+ def content_for(key, &blk)
15
+ content_blocks[key.to_sym] = blk
16
+ end
17
+
18
+ def content_blocks
19
+ $content_blocks ||= Hash.new
20
+ $content_blocks[page.path] ||= Hash.new
21
+ end
22
+
23
+ def has_content?(key)
24
+ content_blocks.member? key.to_sym
25
+ end
26
+
27
+ def yield_content(key, *args)
28
+ content = content_blocks[key.to_sym]
29
+ if respond_to?(:block_is_haml?) && block_is_haml?(content)
30
+ capture_haml(*args, &content)
31
+ elsif content
32
+ content.call(*args)
33
+ end
34
+ end
13
35
  end
14
36
  end
data/lib/hyde/page.rb CHANGED
@@ -3,7 +3,7 @@ class Page
3
3
  attr_reader :project
4
4
  attr_reader :file
5
5
 
6
- def self.[](id, project=$project)
6
+ def self.[](id, project=Hyde.project)
7
7
  site_path = root_path(project)
8
8
  return nil if site_path.nil?
9
9
 
@@ -33,7 +33,7 @@ class Page
33
33
  page
34
34
  end
35
35
 
36
- def initialize(file, project=$project)
36
+ def initialize(file, project=Hyde.project)
37
37
  @file = File.expand_path(file) if file.is_a?(String)
38
38
  @project = project
39
39
  raise Error if project.nil?
@@ -125,19 +125,14 @@ class Page
125
125
  prefix == File.expand_path(@file)[0...prefix.size]
126
126
  end
127
127
 
128
- def content(locals={}, &blk)
128
+ def content(locals={}, tilt_options={}, &blk)
129
129
  return markup unless tilt?
130
- # Build scope
131
- scope = self.dup
132
- scope.extend Helpers
133
- scope.meta.merge! locals
134
-
135
- tilt.render(scope, &blk)
130
+ tilt(tilt_options).render(dup.extend(Helpers), locals, &blk)
136
131
  end
137
132
 
138
- def to_html(locals={}, &blk)
139
- html = content(locals, &blk)
140
- html = layout.to_html(locals) { html } if layout?
133
+ def to_html(locals={}, tilt_options={}, &blk)
134
+ html = content(locals, tilt_options, &blk)
135
+ html = layout.to_html(locals, tilt_options) { html } if layout?
141
136
  html
142
137
  end
143
138
 
@@ -165,7 +160,7 @@ class Page
165
160
  FileUtils.mkdir_p File.dirname(out)
166
161
 
167
162
  if tilt?
168
- File.open(out, 'w') { |f| f.write to_html }
163
+ File.open(out, 'w') { |f| f.write to_html({}, :build => true) }
169
164
  else
170
165
  FileUtils.cp file, out
171
166
  end
@@ -186,13 +181,13 @@ class Page
186
181
  end
187
182
 
188
183
  # Returns the tilt layout.
189
- def tilt
184
+ def tilt(tilt_options={})
190
185
  if tilt?
191
186
  parts
192
187
  # HAML options and such (like :escape_html)
193
- options = project.config.tilt_options_for(@file)
188
+ options = project.config.tilt_options_for(@file, tilt_options)
194
189
  offset = @offset || 1
195
- @tilt ||= Tilt.new(@file, offset, options) { markup }
190
+ Tilt.new(@file, offset, options) { markup }
196
191
  end
197
192
  end
198
193
 
data/lib/hyde/project.rb CHANGED
@@ -2,7 +2,7 @@ class Hyde
2
2
  class Project
3
3
  def initialize(root=Dir.pwd)
4
4
  @root = root
5
- $project = self
5
+ Hyde.project = self
6
6
 
7
7
  validate_version
8
8
  load_extensions
@@ -64,7 +64,7 @@ class Project
64
64
  specs = [*config.ignore].map { |s| root(s) }
65
65
  specs << config_file
66
66
  [:layouts, :extensions, :partials, :output].each do |aspect|
67
- specs << path(aspect, '**/*') if path(aspect)
67
+ specs << path(aspect, '**/*') if path(aspect) && path(aspect) != path(:site)
68
68
  end
69
69
  specs.compact.map { |s| Dir[s] }.flatten.uniq
70
70
  end
data/lib/hyde/server.rb CHANGED
@@ -11,7 +11,7 @@ class Hyde
11
11
  def not_found
12
12
  show_status nil
13
13
  res.status = 404
14
- res.write "404"
14
+ res.write "<h1>File Not Found</h1><p>The path <code>#{env['PATH_INFO']}</code> was not found." + " "*1024
15
15
  end
16
16
 
17
17
  def options
@@ -26,7 +26,7 @@ class Hyde
26
26
  status = page ? "\033[0;32m[ OK ]" : "\033[0;31m[404 ]"
27
27
  verb = get ? 'GET ' : (post ? 'POST' : '')
28
28
  puts "%s\033[0;m %s %s" % [ status, verb, env['PATH_INFO'] ]
29
- puts " src: #{page.filepath} (#{page.tilt_engine_name})" if page.tilt?
29
+ puts " src: #{page.filepath} (#{page.tilt_engine_name})" if page && page.tilt?
30
30
  end
31
31
  end
32
32
 
data/lib/hyde.rb CHANGED
@@ -15,7 +15,7 @@ require 'shake'
15
15
  Tilt.mappings['html'] = Tilt.mappings['erb']
16
16
 
17
17
  class Hyde
18
- VERSION = "0.1.7"
18
+ VERSION = "0.1.8"
19
19
  PREFIX = File.expand_path('../', __FILE__)
20
20
 
21
21
  Error = Class.new(StandardError)
@@ -35,7 +35,12 @@ class Hyde
35
35
  autoload :Partial, "#{PREFIX}/hyde/partial"
36
36
  autoload :Helpers, "#{PREFIX}/hyde/helpers"
37
37
 
38
- def self.version
39
- VERSION
38
+ class << self
39
+ # The latest project.
40
+ attr_accessor :project
41
+
42
+ def version
43
+ VERSION
44
+ end
40
45
  end
41
46
  end
@@ -0,0 +1,16 @@
1
+ hyde_requirement: 0.1
2
+ site_path: site
3
+ extensions_path: extensions
4
+ output_path: public
5
+ ignore:
6
+ - **/*~
7
+ - **/compass/**/*
8
+ - **/_*.scss
9
+
10
+ tilt_options:
11
+ scss:
12
+ :line_numbers: true
13
+
14
+ tilt_build_options:
15
+ scss:
16
+ :line_numbers: false
@@ -0,0 +1 @@
1
+ div { a { color: red; } }
@@ -0,0 +1 @@
1
+ <h1>ello</h1>
@@ -0,0 +1,10 @@
1
+ hyde_requirement: 0.1
2
+ site_path: site
3
+ extensions_path: extensions
4
+ output_path: public
5
+ partials_path: site
6
+ ignore:
7
+ - **/*~
8
+ - **/h*
9
+ - **/compass/**/*
10
+ - **/_*.scss
@@ -0,0 +1 @@
1
+ %h1 ello
@@ -0,0 +1 @@
1
+ xxx
@@ -0,0 +1,18 @@
1
+
2
+ require File.expand_path('../../helper', __FILE__)
3
+
4
+ class BuildOptionsTest < TestCase
5
+ setup do
6
+ @path = fixture('build_options')
7
+ @project = Project.new(@path)
8
+ Dir.chdir @path
9
+ end
10
+
11
+ test "yada" do
12
+ raw = Page['/style.css'].to_html
13
+ built = Page['/style.css'].to_html({}, :build => true)
14
+
15
+ assert !built.include?("line 1")
16
+ assert raw.include?("line 1")
17
+ end
18
+ end
@@ -65,6 +65,10 @@ class HydeTest < TestCase
65
65
  assert_fixture_works fixture('sort')
66
66
  end
67
67
 
68
+ test "fixture ignores" do
69
+ assert_fixture_works fixture('ignores')
70
+ end
71
+
68
72
  test "fixture metadata" do
69
73
  assert_fixture_works fixture('metadata')
70
74
  end
@@ -72,6 +76,10 @@ class HydeTest < TestCase
72
76
  test "fixture nested_layout" do
73
77
  assert_fixture_works fixture('nested_layout')
74
78
  end
79
+
80
+ test "fixture build_options" do
81
+ assert_fixture_works fixture('build_options')
82
+ end
75
83
 
76
84
  test "fixture fail_type" do
77
85
  assert_fixture_fails(fixture('fail_type')) { |e|
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hydeweb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.7
5
+ version: 0.1.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rico Sta. Cruz
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-22 00:00:00 +08:00
13
+ date: 2011-02-25 00:00:00 +08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -19,9 +19,9 @@ dependencies:
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
- - - ">="
22
+ - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: 0.1.2
24
+ version: "0.1"
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
@@ -93,6 +93,8 @@ files:
93
93
  - lib/hyde/server.rb
94
94
  - lib/hyde/set.rb
95
95
  - lib/hyde.rb
96
+ - test/fixture/build_options/hyde.conf
97
+ - test/fixture/build_options/site/style.scss
96
98
  - test/fixture/extensions/control/index.html
97
99
  - test/fixture/extensions/extensions/a/a.rb
98
100
  - test/fixture/extensions/hyde.conf
@@ -105,6 +107,10 @@ files:
105
107
  - test/fixture/html/control/index.html
106
108
  - test/fixture/html/hyde.conf
107
109
  - test/fixture/html/site/index.html
110
+ - test/fixture/ignores/control/about.html
111
+ - test/fixture/ignores/hyde.conf
112
+ - test/fixture/ignores/site/about.haml
113
+ - test/fixture/ignores/site/hi.haml
108
114
  - test/fixture/metadata/control/index.html
109
115
  - test/fixture/metadata/hyde.conf
110
116
  - test/fixture/metadata/site/index.haml
@@ -153,6 +159,7 @@ files:
153
159
  - test/fixture/subclass/layouts/post.haml
154
160
  - test/fixture/subclass/site/index.haml
155
161
  - test/helper.rb
162
+ - test/unit/build_options_test.rb
156
163
  - test/unit/extensions_test.rb
157
164
  - test/unit/fixture_test.rb
158
165
  - test/unit/hyde_test.rb
@@ -165,6 +172,7 @@ files:
165
172
  - data/new_site/README.md
166
173
  - HISTORY.md
167
174
  - README.md
175
+ - TODO.md
168
176
  - Rakefile
169
177
  - AUTHORS
170
178
  has_rdoc: true