hydeweb 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,15 @@
1
+ v0.1.2
2
+ ------
3
+
4
+ - Allow `hyde create .` to add a hyde.conf in the current folder.
5
+ - Revamp the help screen.
6
+ - Fix: change the default load path for Sass/SCSS to 'css'.
7
+ - Add Page#depth.
8
+ - Fix Page#breadcrumbs.
9
+ - Fix Page#parent.
10
+ - Add the `rel` helper.
11
+ - Generated Hyde projects are now Rack-compatible.
12
+
1
13
  v0.1.1
2
14
  ------
3
15
 
@@ -11,8 +23,13 @@ v0.1.1
11
23
  v0.1.0
12
24
  ------
13
25
 
14
- - Complete rewrite. Many thing have been deprecated.
15
- - Now uses Tilt and Shake.
26
+ **Complete rewrite.** Many thing have been deprecated.
27
+
28
+ - Now uses Tilt (for templates), Shake (for CLI) and Cuba (for the server).
29
+ - Now supports everything Tilt supports: CoffeeScript, Liquid, etc.
30
+ - Allow `tilt_options` in hyde.conf.
31
+ - Old extensions will be broken (but who made any yet, anyway?)
32
+ - Update the `hyde create` template's gitignore file to account for _public.
16
33
 
17
34
  v0.0.8
18
35
  ------
@@ -1,18 +1,10 @@
1
- {sitename}
2
- ==========
3
-
4
- This is my site.
5
-
6
-
7
1
  Instructions
8
2
  ------------
9
3
 
10
4
  1. Make sure Ruby (>= v1.8) is installed.
11
- 2. Install the hydeweb gem: `gem install hydeweb --pre -v "~> 0.1"`
5
+ 2. Install the hydeweb gem: `gem install hydeweb`
12
6
  3. Build the site HTML files by typing: `hyde build`
13
7
 
14
- You may also type `hyde start` to serve the files in a local web server.
15
-
16
- (If #2 fails, you may need to type `sudo gem install hydeweb` instead)
8
+ (If #2 fails, you may need to type `sudo gem install hydeweb` instead)
17
9
 
18
10
 
@@ -2,9 +2,26 @@
2
2
  %html
3
3
  %head
4
4
  %title= page.title
5
+
6
+ %meta(charset='UTF-8')
7
+ -# Use the latest IE engine, or Chrome frame.
8
+ %meta(http-equiv='X-UA-Compatible' content='IE=edge,chrome=1')
9
+
10
+ -# Mobile viewport optimization. j.mp/bplateviewport
11
+ %meta(name='viewport' content='width=device-width, initial-scale=1.0')
12
+
13
+ -# Standard SEO meta
14
+ - if page.meta.keywords
15
+ %meta{:name => 'keywords', :content => page.meta.keywords}
16
+ - if page.meta.description
17
+ %meta{:name => 'description', :content => page.meta.description}
18
+
19
+ %link{:rel => 'stylesheet', :href => '/css/style.css'}
20
+
5
21
  %body
6
22
  #content
7
23
  != yield
24
+
8
25
  %div#footer
9
26
  %hr
10
27
  %p Generated by Hyde
@@ -0,0 +1,8 @@
1
+ # This file exists to make this project Rack-compatible.
2
+ # You may delete it if you're not concerned about this.
3
+
4
+ require 'hyde'
5
+ require 'hyde/server'
6
+
7
+ Hyde::Project.new File.dirname(__FILE__)
8
+ run Hyde::Server
@@ -15,6 +15,8 @@ partials_path: _layouts
15
15
  ignore:
16
16
  - **/*~
17
17
  - README*
18
+ - config.ru
19
+ - **/.*
18
20
  - **/_*.scss
19
21
 
20
22
  # Optional options for layout engines
@@ -22,5 +24,5 @@ tilt_options:
22
24
  haml:
23
25
  :escape_html: true
24
26
  scss:
25
- :load_paths: [ 'site/css' ]
27
+ :load_paths: [ 'css' ]
26
28
 
@@ -1,6 +1,29 @@
1
1
  class Hyde
2
2
  class CLI
3
3
  module Helpers
4
+ def show_help_for(task)
5
+ name = params.first
6
+ task = task(name)
7
+ pass "No such command. Try: #{executable} help" unless task
8
+
9
+ help = task.help
10
+ if help
11
+ help.each { |line| err line }
12
+ err
13
+ else
14
+ err "Usage: #{executable} #{task.usage || name}"
15
+ err "#{task.description}." if task.description
16
+ end
17
+ end
18
+
19
+ def tasks_for(category)
20
+ tasks.select { |name, t| t.category == category }
21
+ end
22
+
23
+ def other_tasks
24
+ tasks.select { |name, t| t.category.nil? }
25
+ end
26
+
4
27
  def say_info(str)
5
28
  say_status '*', str, 30
6
29
  end
@@ -12,12 +35,20 @@ module Helpers
12
35
  end
13
36
 
14
37
  def no_project
15
- "No project file here."
38
+ "Error: This is not a Hyde project.\n" +
39
+ "You may convert it into one by creating a config file:\n" +
40
+ " $ #{executable} create .\n\n" +
41
+ "You may also create an empty project in a new directory:\n" +
42
+ " $ #{executable} create NAME\n"
43
+ end
44
+
45
+ def project?
46
+ !! @hydefile
16
47
  end
17
48
 
18
49
  def project
19
50
  @project ||= begin
20
- pass no_project unless @hydefile
51
+ pass no_project unless project?
21
52
  Dir.chdir File.dirname(@hydefile)
22
53
 
23
54
  begin
data/lib/hyde/cli.rb CHANGED
@@ -7,10 +7,16 @@ class CLI < Shake
7
7
 
8
8
  task(:create) do
9
9
  wrong_usage unless params.size == 1
10
-
11
10
  template = File.expand_path('../../../data/new_site', __FILE__)
12
11
  target = params.first
13
12
 
13
+ if target == '.'
14
+ pass "This is already a Hyde project." if @hydefile
15
+ FileUtils.cp_r File.join(template, 'hyde.conf'), target
16
+ say_status :create, 'hyde.conf'
17
+ pass
18
+ end
19
+
14
20
  pass "Error: target directory already exists." if File.directory?(target)
15
21
 
16
22
  puts "Creating files in #{target}:"
@@ -36,6 +42,7 @@ class CLI < Shake
36
42
 
37
43
  task.description = "Starts a new Hyde project"
38
44
  task.usage = "create NAME"
45
+ task.category = :create
39
46
 
40
47
  task(:build) do
41
48
  pre = project.config.output_path
@@ -56,6 +63,7 @@ class CLI < Shake
56
63
  end
57
64
 
58
65
  task.description = "Builds the current project"
66
+ task.category = :project
59
67
 
60
68
  task(:start) do
61
69
  project
@@ -69,12 +77,58 @@ class CLI < Shake
69
77
  end
70
78
 
71
79
  task.description = "Starts the server"
80
+ task.category = :project
72
81
 
73
82
  task(:version) do
74
83
  puts "Hyde #{Hyde::VERSION}"
75
84
  end
76
85
 
77
86
  task.description = "Shows the current version"
87
+ task.category = :misc
88
+
89
+ task(:help) do
90
+ show_help_for(params.first) and pass if params.any?
91
+
92
+ show_task = Proc.new { |name, t| err " %-20s %s" % [ t.usage || name, t.description ] }
93
+
94
+ err "Usage: #{executable} <command>"
95
+
96
+ err "\nCommands:"
97
+ tasks_for(:create).each &show_task
98
+ err "\nProject commands:"
99
+ tasks_for(:project).each &show_task
100
+ if other_tasks.any?
101
+ err "\nOthers:"
102
+ other_tasks.each &show_task
103
+ end
104
+ err "\nMisc commands:"
105
+ tasks_for(:misc).each &show_task
106
+
107
+ unless project?
108
+ err
109
+ err "Get started by typing:"
110
+ err " $ #{executable} create my_project"
111
+ err
112
+ err "Type `#{executable} help COMMAND` for additional help on a command."
113
+ end
114
+ end
115
+
116
+ task.description = "Shows help for a given command"
117
+ task.usage = "help [COMMAND]"
118
+ task.category = :misc
119
+
120
+ invalid do
121
+ task = task(command)
122
+ if task
123
+ err "Invalid usage."
124
+ err "Try: #{executable} #{task.usage}"
125
+ err
126
+ err "Type `#{executable} help` for more info."
127
+ else
128
+ err "Invalid command: #{command}"
129
+ err "Type `#{executable} help` for more info."
130
+ end
131
+ end
78
132
 
79
133
  def self.run!(options={})
80
134
  @hydefile = options[:file]
data/lib/hyde/config.rb CHANGED
@@ -28,6 +28,8 @@ class Config < OpenStruct
28
28
  @tilt_options ||= begin
29
29
  o = @table[:tilt_options] || Hash.new
30
30
  o['haml'] ||= { :escape_html => true }
31
+ o['scss'] ||= { :load_path => ['css'] }
32
+ o['sass'] ||= { :load_path => ['css'] }
31
33
  o
32
34
  end
33
35
 
data/lib/hyde/helpers.rb CHANGED
@@ -4,5 +4,11 @@ module Helpers
4
4
  partial = Partial[path.to_s, page] or return ''
5
5
  partial.to_html :page => self
6
6
  end
7
+
8
+ def rel(path)
9
+ depth = page.depth
10
+ dotdot = depth > 1 ? ('../' * (page.depth-1)) : './'
11
+ (dotdot[0...-1] + path)
12
+ end
7
13
  end
8
14
  end
data/lib/hyde/page.rb CHANGED
@@ -205,9 +205,15 @@ class Page
205
205
  end
206
206
 
207
207
  def parent
208
- parts = path.split('/')
209
- parent_path = index? ? parts[0...-2] : parts[0...-1]
210
- self.class[parent_path.join('/'), project]
208
+ parts = path.split('/') # ['', 'about', 'index.html']
209
+
210
+ try = lambda { |newpath| p = self.class[newpath, project]; p if p && p.path != path }
211
+
212
+ # Absolute root
213
+ return nil if index? and parts.size <= 2
214
+
215
+ parent = try[parts[0...-1].join('/')] # ['','about'] => '/about'
216
+ parent ||= try['/'] # Home
211
217
  end
212
218
 
213
219
  def children
@@ -243,6 +249,10 @@ class Page
243
249
  parent.nil?
244
250
  end
245
251
 
252
+ def depth
253
+ breadcrumbs.size
254
+ end
255
+
246
256
  protected
247
257
  def default_layout
248
258
  'default' if html?
data/lib/hyde/server.rb CHANGED
@@ -32,10 +32,12 @@ class Hyde
32
32
  on default do
33
33
  begin
34
34
  page = Hyde::Page[env['PATH_INFO']] or break not_found
35
- res['Content-Type'] = page.mime_type
35
+ type = page.mime_type
36
+ res['Content-Type'] = type if type
36
37
  res.write page.to_html
37
38
  show_status page
38
39
  rescue => e
40
+ res['Content-Type'] = 'text/html'
39
41
  res.write "<h1>#{e.class}: #{e.message}</h1><ul>#{e.backtrace.map{|l|"<li>#{l}</li>"}.join('')}</ul>"
40
42
  end
41
43
  end
data/lib/hyde.rb CHANGED
@@ -9,7 +9,7 @@ require 'tilt'
9
9
  require 'shake'
10
10
 
11
11
  class Hyde
12
- VERSION = "0.1.1"
12
+ VERSION = "0.1.2"
13
13
  PREFIX = File.expand_path('../', __FILE__)
14
14
 
15
15
  Error = Class.new(StandardError)
@@ -0,0 +1 @@
1
+ <h1>hi</h1>
@@ -0,0 +1,3 @@
1
+ layout: false
2
+ --
3
+ %h1 hi
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../../helper', __FILE__)
2
+
3
+ class PageTest < TestCase
4
+ setup do
5
+ @path = fixture('one')
6
+ @project = Project.new(@path)
7
+ Dir.chdir @path
8
+ end
9
+
10
+ test "root" do
11
+ @page = Page['/']
12
+ assert @page.index?
13
+ assert @page.root?
14
+ end
15
+
16
+ test "breadcrumbs" do
17
+ assert_equal %w(/index.html /about/index.css), Page['/about/index.css'].breadcrumbs.map(&:path)
18
+ assert_equal %w(/index.html /about/index.css /about/us.html), Page['/about/us.html'].breadcrumbs.map(&:path)
19
+ assert_equal %w(/index.html /css/style.css), Page['/css/style.css'].breadcrumbs.map(&:path)
20
+ assert_equal %w(/index.html), Page['/'].breadcrumbs.map(&:path)
21
+ end
22
+
23
+ test "parent" do
24
+ assert Page['/'].parent.nil?
25
+ assert Page['/css/style.css'].parent.path == '/index.html'
26
+ end
27
+ 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.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rico Sta. Cruz
@@ -106,6 +106,7 @@ files:
106
106
  - test/fixture/nested_layout/layouts/post.haml
107
107
  - test/fixture/nested_layout/site/index.haml
108
108
  - test/fixture/one/control/about/index.css
109
+ - test/fixture/one/control/about/us.html
109
110
  - test/fixture/one/control/cheers.html
110
111
  - test/fixture/one/control/css/style.css
111
112
  - test/fixture/one/control/hello.html
@@ -115,6 +116,7 @@ files:
115
116
  - test/fixture/one/layouts/default.haml
116
117
  - test/fixture/one/partials/menu.haml
117
118
  - test/fixture/one/site/about/index.scss
119
+ - test/fixture/one/site/about/us.haml
118
120
  - test/fixture/one/site/cheers.html.haml
119
121
  - test/fixture/one/site/css/style.scss
120
122
  - test/fixture/one/site/hello.haml
@@ -141,7 +143,9 @@ files:
141
143
  - test/unit/extensions_test.rb
142
144
  - test/unit/fixture_test.rb
143
145
  - test/unit/hyde_test.rb
146
+ - test/unit/page_test.rb
144
147
  - data/new_site/_layouts/default.haml
148
+ - data/new_site/config.ru
145
149
  - data/new_site/hyde.conf
146
150
  - data/new_site/index.haml
147
151
  - data/new_site/README.md