hydeweb 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,17 @@
1
+ v0.1.3
2
+ ------
3
+
4
+ - .html files are now being treated as .erb.
5
+ - Implement `page.children.find`.
6
+ - Implement `page.children.except`.
7
+ - Fix #children and sorting giving errors.
8
+ - Fix #siblings.
9
+ - Revise the 'no config file found' error message.
10
+ - Allow `.hyderc` as a filename.
11
+ - Add help for `hyde help start`.
12
+ - Support `hyde start -D` which is a very hackish solution to have
13
+ Hyde start as a daemon.
14
+
1
15
  v0.1.2
2
16
  ------
3
17
 
data/Rakefile CHANGED
@@ -4,8 +4,8 @@ end
4
4
 
5
5
  task :default => :test
6
6
 
7
- task :gembuild do
7
+ task :gemrelease do
8
8
  require './lib/hyde'
9
9
  v = Hyde.version
10
- system "joe build && git commit -a -m \"Update to version #{v}.\" && git tag v#{v}"
10
+ system "joe build && git commit -a -m \"Update to version #{v}.\" && git tag v#{v} && git push && joe release"
11
11
  end
data/bin/hyde CHANGED
@@ -3,5 +3,6 @@ $:.push File.expand_path('../../lib', __FILE__)
3
3
 
4
4
  require 'hyde'
5
5
 
6
- hydefile = Hyde::CLI.find_in_project('hyde.conf')
6
+ hydefile = Hyde::CONFIG_FILES.inject { |a, fname| a ||= Hyde::CLI.find_in_project(fname) }
7
+
7
8
  Hyde::CLI.run! :file => hydefile
data/bin/hyde01 CHANGED
@@ -3,5 +3,6 @@ $:.push File.expand_path('../../lib', __FILE__)
3
3
 
4
4
  require 'hyde'
5
5
 
6
- hydefile = Hyde::CLI.find_in_project('hyde.conf')
6
+ hydefile = Hyde::CONFIG_FILES.inject { |a, fname| a ||= Hyde::CLI.find_in_project(fname) }
7
+
7
8
  Hyde::CLI.run! :file => hydefile
@@ -4,7 +4,7 @@ hyde_requirement: 0.1
4
4
 
5
5
  # The folder where the site's source files are kept.
6
6
  site_path: .
7
- output_path: _public
7
+ output_path: _output
8
8
 
9
9
  # Other paths:
10
10
  layouts_path: _layouts
@@ -8,8 +8,11 @@ require 'yaml'
8
8
  require 'tilt'
9
9
  require 'shake'
10
10
 
11
+ # HTML files as ERB
12
+ Tilt.mappings['html'] = Tilt.mappings['erb']
13
+
11
14
  class Hyde
12
- VERSION = "0.1.2"
15
+ VERSION = "0.1.3"
13
16
  PREFIX = File.expand_path('../', __FILE__)
14
17
 
15
18
  Error = Class.new(StandardError)
@@ -17,11 +20,15 @@ class Hyde
17
20
  VersionError = Class.new(Error)
18
21
  NoGemError = Class.new(Error)
19
22
 
23
+ # Allowed config filenames
24
+ CONFIG_FILES = ['hyde.conf', '.hyderc']
25
+
20
26
  autoload :Project, "#{PREFIX}/hyde/project"
21
27
  autoload :Page, "#{PREFIX}/hyde/page"
22
28
  autoload :Meta, "#{PREFIX}/hyde/meta"
23
29
  autoload :Config, "#{PREFIX}/hyde/config"
24
30
  autoload :CLI, "#{PREFIX}/hyde/cli"
31
+ autoload :Set, "#{PREFIX}/hyde/set"
25
32
  autoload :Layout, "#{PREFIX}/hyde/layout"
26
33
  autoload :Partial, "#{PREFIX}/hyde/partial"
27
34
  autoload :Helpers, "#{PREFIX}/hyde/helpers"
@@ -68,16 +68,37 @@ class CLI < Shake
68
68
  task(:start) do
69
69
  project
70
70
 
71
- port = (params.extract('-p') || 4833).to_i
72
- host = (params.extract('-o') || '0.0.0.0')
71
+ port = (params.extract('-p') || 4833).to_i
72
+ host = (params.extract('-o') || '0.0.0.0')
73
+ daemon = (!! params.delete('-D'))
73
74
 
74
75
  require 'hyde/server'
75
76
 
76
- Hyde::Server.run! :Host => host, :Port => port
77
+ if daemon
78
+ pid = fork { Hyde::Server.run! :Host => host, :Port => port, :quiet => true }
79
+ sleep 2
80
+ puts
81
+ puts "Listening on #{host}:#{port} on pid #{pid}."
82
+ puts "To stop: kill #{pid}"
83
+ else
84
+ Hyde::Server.run! :Host => host, :Port => port
85
+ end
77
86
  end
78
87
 
79
88
  task.description = "Starts the server"
80
89
  task.category = :project
90
+ task.help = %{
91
+ Usage:
92
+
93
+ #{executable} start [-p PORT] [-o HOST] [-D]
94
+
95
+ Starts an HTTP server so you may rapidly test your project locally.
96
+
97
+ If the -p and/or -o is specified, it will listen on the specified HOST:PORT.
98
+ Otherwise, the default is 0.0.0.0:4833.
99
+
100
+ If -D is specified, it goes into daemon mode.
101
+ }.gsub(/^ {4}/, '').strip.split("\n")
81
102
 
82
103
  task(:version) do
83
104
  puts "Hyde #{Hyde::VERSION}"
@@ -108,9 +129,9 @@ class CLI < Shake
108
129
  err
109
130
  err "Get started by typing:"
110
131
  err " $ #{executable} create my_project"
111
- err
112
- err "Type `#{executable} help COMMAND` for additional help on a command."
113
132
  end
133
+ err
134
+ err "Type `#{executable} help COMMAND` for additional help on a command."
114
135
  end
115
136
 
116
137
  task.description = "Shows help for a given command"
@@ -1,8 +1,7 @@
1
1
  class Hyde
2
2
  class CLI
3
3
  module Helpers
4
- def show_help_for(task)
5
- name = params.first
4
+ def show_help_for(name)
6
5
  task = task(name)
7
6
  pass "No such command. Try: #{executable} help" unless task
8
7
 
@@ -35,8 +34,9 @@ module Helpers
35
34
  end
36
35
 
37
36
  def no_project
38
- "Error: This is not a Hyde project.\n" +
39
- "You may convert it into one by creating a config file:\n" +
37
+ "Error: no Hyde config file found.\n" +
38
+ "(Looked for #{Hyde::CONFIG_FILES.join(', ')})\n\n" +
39
+ "You start by creating a config file for this project:\n" +
40
40
  " $ #{executable} create .\n\n" +
41
41
  "You may also create an empty project in a new directory:\n" +
42
42
  " $ #{executable} create NAME\n"
@@ -3,5 +3,9 @@ class Meta < OpenStruct
3
3
  def merge!(hash)
4
4
  @table.merge(hash)
5
5
  end
6
+
7
+ def [](id)
8
+ @table[id.to_sym]
9
+ end
6
10
  end
7
11
  end
@@ -65,6 +65,10 @@ class Page
65
65
 
66
66
  alias to_s title
67
67
 
68
+ def position
69
+ meta[:position] || title
70
+ end
71
+
68
72
  def <=>(other)
69
73
  result = self.position <=> other.position
70
74
  result ||= self.position.to_s <=> other.position.to_s
@@ -226,15 +230,18 @@ class Page
226
230
  File.expand_path("../#{base}/*", @file)
227
231
  end
228
232
 
229
- Dir[files].reject { |f| f == @file }.map { |f| self.class[f, project] }.compact.sort
233
+ Set.new Dir[files].reject { |f| f == @file }.map { |f| self.class[f, project] }.compact.sort
230
234
  end
231
235
 
232
236
  def siblings
233
- p = parent and p.children
237
+ pages = (p = parent and p.children)
238
+ return Set.new unless pages
239
+ return Set.new unless pages.include?(self)
240
+ Set.new(pages)
234
241
  end
235
242
 
236
243
  def breadcrumbs
237
- parent? ? (parent.breadcrumbs + [self]) : [self]
244
+ Set.new (parent? ? (parent.breadcrumbs + [self]) : [self])
238
245
  end
239
246
 
240
247
  def index?
@@ -253,6 +260,21 @@ class Page
253
260
  breadcrumbs.size
254
261
  end
255
262
 
263
+ def next
264
+ page = self
265
+ while true do
266
+ page.siblings.index(self)
267
+ end
268
+ end
269
+
270
+ def ==(other)
271
+ self.path == other.path
272
+ end
273
+
274
+ def inspect
275
+ "<##{self.class.name} #{path.inspect}>"
276
+ end
277
+
256
278
  protected
257
279
  def default_layout
258
280
  'default' if html?
@@ -15,6 +15,7 @@ class Hyde
15
15
  end
16
16
 
17
17
  def show_status(page)
18
+ return if @options[:quiet]
18
19
  path = env['PATH_INFO']
19
20
  return if path == '/favicon.ico'
20
21
 
@@ -48,6 +49,7 @@ end
48
49
  module Hyde::Server
49
50
  # :Host, :Port
50
51
  def self.run!(options={})
52
+ @options = options
51
53
  handler = rack_handler or return false
52
54
  handler.run self, options
53
55
  end
@@ -0,0 +1,23 @@
1
+ class Hyde
2
+ class Set < Array
3
+ # Filters a set by given metadata criteria.
4
+ #
5
+ # @example
6
+ # Page['/'].children.find(layout: 'default')
7
+ #
8
+ def find(by={})
9
+ self.class.new(select do |page|
10
+ by.inject(true) { |b, (field, value)| b &&= (page.meta.send(field) == value) }
11
+ end)
12
+ end
13
+
14
+ # Filters a set by removing items matching the given metadata criteria.
15
+ # This is the opposite of #find.
16
+ #
17
+ def except(by={})
18
+ self.class.new(reject do |page|
19
+ by.inject(true) { |b, (field, value)| b &&= (page.meta.send(field) == value) }
20
+ end)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1 @@
1
+ <h1>hey</h1>
@@ -0,0 +1,2 @@
1
+ <h1>Welcome.</h1>
2
+ Hello
@@ -0,0 +1,8 @@
1
+ hyde_requirement: 0.1
2
+ site_path: site
3
+ extensions_path: extensions
4
+ output_path: public
5
+ ignore:
6
+ - **/*~
7
+ - **/compass/**/*
8
+ - **/_*.scss
@@ -0,0 +1,2 @@
1
+ <h1>Welcome.</h1>
2
+ <%= "Hello" %>
File without changes
File without changes
@@ -1 +1,3 @@
1
+ hello: world
2
+ --
1
3
  %h1 Welcome!
@@ -1 +1,3 @@
1
+ layout: false
2
+ --
1
3
  Hello.
@@ -0,0 +1,6 @@
1
+ <li>
2
+ <a href='/about/intrepid.html'>One, intrepid</a>
3
+ </li>
4
+ <li>
5
+ <a href='/about/hardy.html'>Two, hardy</a>
6
+ </li>
@@ -3,11 +3,11 @@ $:.push File.expand_path('../../lib', __FILE__)
3
3
  require 'hyde'
4
4
  require 'contest'
5
5
 
6
- # Unpack
7
- Page = Hyde::Page
8
- Project = Hyde::Project
9
-
10
6
  class TestCase < Test::Unit::TestCase
7
+ # Shorthand
8
+ Page = Hyde::Page
9
+ Project = Hyde::Project
10
+
11
11
  def fixture(*a)
12
12
  path = File.expand_path('../fixture', __FILE__)
13
13
  File.join path, *a
@@ -7,10 +7,6 @@ class HydeTest < TestCase
7
7
  Dir.chdir @path
8
8
  end
9
9
 
10
- test "hi" do
11
- #y @project.pages.map { |page| y html: page.to_html, path: page.path, file: page.file }
12
- end
13
-
14
10
  test "build" do
15
11
  @project.pages.each { |page| page.write }
16
12
  end
@@ -22,6 +18,7 @@ class HydeTest < TestCase
22
18
  assert_equal Page['/cheers.html'].file, site['cheers.html.haml']
23
19
  assert_equal Page['/hi.html'].file, site['hi.html']
24
20
  assert_equal Page['/hi.yo'].file, site['hi.html']
21
+ assert_equal Page['/hi'].file, site['hi.html']
25
22
  assert_equal Page['/css/style.css'].file, site['css/style.scss']
26
23
  assert_equal Page['/css/style.css'].file, site['css/style.scss']
27
24
  assert_equal Page['/about'].file, site['about/index.scss']
@@ -24,4 +24,35 @@ class PageTest < TestCase
24
24
  assert Page['/'].parent.nil?
25
25
  assert Page['/css/style.css'].parent.path == '/index.html'
26
26
  end
27
+
28
+ test "siblings" do
29
+ # Because it has no parent, technically
30
+ page = Page['/about/index.css']
31
+ assert page.siblings.empty?
32
+
33
+ page = Page['/hello.html']
34
+ assert_equal %w(/cheers.html /hello.html /hi.html), page.siblings.map(&:path)
35
+ end
36
+
37
+ test "mimes" do
38
+ assert !Page['/css/style.css'].html?
39
+ assert Page['/'].html?
40
+ assert_equal 'text/css', Page['/css/style.css'].mime_type
41
+ assert_equal 'text/html', Page['/about/us.html'].mime_type
42
+ assert_equal 'html', Page['/about/us.html'].default_ext
43
+ assert_equal 'css', Page['/css/style.css'].default_ext
44
+ end
45
+
46
+ test "no layout" do
47
+ page = Page['/hi.html']
48
+ assert_equal false, page.meta.layout
49
+ assert_equal nil, page.layout
50
+ assert_equal false, page.layout?
51
+ assert_equal page.to_html, page.content
52
+ end
53
+
54
+ test "html pages should be intact" do
55
+ page = Page['/hi']
56
+ assert_equal page.markup, page.content
57
+ end
27
58
  end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../../helper', __FILE__)
2
+
3
+ class SetTest < TestCase
4
+ setup do
5
+ @path = fixture('one')
6
+ @project = Project.new(@path)
7
+ Dir.chdir @path
8
+ end
9
+
10
+ test "breadcrumbs" do
11
+ assert Page['/about/index.css'].breadcrumbs.is_a?(Hyde::Set)
12
+ end
13
+
14
+ test "children" do
15
+ assert Page['/'].children.is_a?(Hyde::Set)
16
+ end
17
+
18
+ test "siblings" do
19
+ assert Page['/about'].siblings.is_a?(Hyde::Set)
20
+ end
21
+
22
+ test "children" do
23
+ set = Page['/'].children.find(:hello => 'world')
24
+ assert set.map(&:path) == ['/hello.html']
25
+ end
26
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hydeweb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
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-20 00:00:00 +08:00
13
+ date: 2011-02-22 00:00:00 +08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -91,7 +91,9 @@ files:
91
91
  - lib/hyde/partial.rb
92
92
  - lib/hyde/project.rb
93
93
  - lib/hyde/server.rb
94
+ - lib/hyde/set.rb
94
95
  - lib/hyde.rb
96
+ - test/fixture/extensions/control/index.html
95
97
  - test/fixture/extensions/extensions/a/a.rb
96
98
  - test/fixture/extensions/hyde.conf
97
99
  - test/fixture/extensions/site/index.haml
@@ -100,6 +102,9 @@ files:
100
102
  - test/fixture/fail_type/control/index.html
101
103
  - test/fixture/fail_type/hyde.conf
102
104
  - test/fixture/fail_type/site/index.haml
105
+ - test/fixture/html/control/index.html
106
+ - test/fixture/html/hyde.conf
107
+ - test/fixture/html/site/index.html
103
108
  - test/fixture/nested_layout/control/index.html
104
109
  - test/fixture/nested_layout/hyde.conf
105
110
  - test/fixture/nested_layout/layouts/default.haml
@@ -108,6 +113,7 @@ files:
108
113
  - test/fixture/one/control/about/index.css
109
114
  - test/fixture/one/control/about/us.html
110
115
  - test/fixture/one/control/cheers.html
116
+ - test/fixture/one/control/css/bar.css
111
117
  - test/fixture/one/control/css/style.css
112
118
  - test/fixture/one/control/hello.html
113
119
  - test/fixture/one/control/hi.html
@@ -118,6 +124,7 @@ files:
118
124
  - test/fixture/one/site/about/index.scss
119
125
  - test/fixture/one/site/about/us.haml
120
126
  - test/fixture/one/site/cheers.html.haml
127
+ - test/fixture/one/site/css/bar.scss
121
128
  - test/fixture/one/site/css/style.scss
122
129
  - test/fixture/one/site/hello.haml
123
130
  - test/fixture/one/site/hi.html
@@ -129,6 +136,9 @@ files:
129
136
  - test/fixture/parent/site/about/index.haml
130
137
  - test/fixture/parent/site/about/us.haml
131
138
  - test/fixture/parent/site/index.haml
139
+ - test/fixture/sort/control/about/hardy.html
140
+ - test/fixture/sort/control/about/intrepid.html
141
+ - test/fixture/sort/control/about.html
132
142
  - test/fixture/sort/hyde.conf
133
143
  - test/fixture/sort/site/about/hardy.haml
134
144
  - test/fixture/sort/site/about/intrepid.haml
@@ -144,6 +154,7 @@ files:
144
154
  - test/unit/fixture_test.rb
145
155
  - test/unit/hyde_test.rb
146
156
  - test/unit/page_test.rb
157
+ - test/unit/set_test.rb
147
158
  - data/new_site/_layouts/default.haml
148
159
  - data/new_site/config.ru
149
160
  - data/new_site/hyde.conf