hyper 0.3.0beta1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +32 -9
- data/bin/hyper +7 -2
- data/lib/hyper.rb +15 -15
- data/lib/hyper/application.rb +41 -0
- data/lib/hyper/generator.rb +0 -1
- data/lib/hyper/static.rb +0 -1
- data/lib/hyper/utils.rb +1 -2
- data/lib/hyper/version.rb +1 -1
- metadata +9 -13
- data/lib/hyper/response.rb +0 -34
data/README.md
CHANGED
|
@@ -14,6 +14,16 @@ Five steps from install to a functioning website:
|
|
|
14
14
|
|
|
15
15
|
Point your browser at <a href="http://0.0.0.0:9292/">0.0.0.0:9292</a> and you'll see your website's home page.
|
|
16
16
|
|
|
17
|
+
## Deployment
|
|
18
|
+
|
|
19
|
+
If you love Heroku, deployment is easy:
|
|
20
|
+
|
|
21
|
+
$ cd my_website
|
|
22
|
+
$ heroku create
|
|
23
|
+
$ git push heroku master
|
|
24
|
+
|
|
25
|
+
Any other rack-compatible host should work too.
|
|
26
|
+
|
|
17
27
|
## Adding Content
|
|
18
28
|
|
|
19
29
|
To add content to your site, you just need to know two things:
|
|
@@ -29,19 +39,32 @@ Also note: your home page content goes in <code>views/index.html.erb</code>; Hyp
|
|
|
29
39
|
|
|
30
40
|
Put your stylesheets, images, javascripts, etc in <code>public</code>: Hyper will handle the rest. When referencing these files in your HTML, drop the "public" from the path — <code>public/images/logo.png</code> should become <code><img src="/images/logo.png" /></code>.
|
|
31
41
|
|
|
32
|
-
##
|
|
42
|
+
## Helper Code
|
|
33
43
|
|
|
34
|
-
|
|
44
|
+
Put your custom helper methods in <code>lib/helper.rb</code>:
|
|
35
45
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
# in lib/helper.rb
|
|
47
|
+
module Hyper::Helper
|
|
48
|
+
def the_time
|
|
49
|
+
Time.now.to_s
|
|
50
|
+
end
|
|
51
|
+
end
|
|
39
52
|
|
|
40
|
-
|
|
53
|
+
# in templates/layout.html.erb
|
|
54
|
+
<html>
|
|
55
|
+
<head>
|
|
56
|
+
<title>Clock</title>
|
|
57
|
+
</head>
|
|
58
|
+
<body>
|
|
59
|
+
<h1>Hello! The time is <%= the_time -%></h1>
|
|
60
|
+
</body>
|
|
61
|
+
</html>
|
|
62
|
+
|
|
63
|
+
Helper methods have access to a <code>request</code> object which is an instance of <a href="http://rack.rubyforge.org/doc/classes/Rack/Request.html"><code>Rack::Request</code></a>.
|
|
41
64
|
|
|
42
65
|
## In-Depth
|
|
43
66
|
|
|
44
|
-
|
|
67
|
+
Hyper is intentionally simple. Once you've generated a new site, you'll get the following files and folders:
|
|
45
68
|
|
|
46
69
|
<table>
|
|
47
70
|
<tr>
|
|
@@ -54,7 +77,7 @@ There's not a whole lot of depth to go into: hyper is intentionally simple. Once
|
|
|
54
77
|
</tr>
|
|
55
78
|
<tr>
|
|
56
79
|
<td><code>templates/views</code></td>
|
|
57
|
-
<td>This is where your page-specific content lives. See "Adding Content for more details
|
|
80
|
+
<td>This is where your page-specific content lives. See "Adding Content" for more details</td>
|
|
58
81
|
</tr>
|
|
59
82
|
<tr>
|
|
60
83
|
<td><code>public</code></td>
|
|
@@ -70,7 +93,7 @@ There's not a whole lot of depth to go into: hyper is intentionally simple. Once
|
|
|
70
93
|
</tr>
|
|
71
94
|
</table>
|
|
72
95
|
|
|
73
|
-
Defaults are set so you don't have to worry about anything outside <code>templates</code> if you don't want to. If you understand rack and want to add middleware, do that in <code>config.ru</code>
|
|
96
|
+
Defaults are set so you don't have to worry about anything outside <code>templates</code> if you don't want to. If you understand rack and want to add middleware, do that in <code>config.ru</code> — note that Hyper already knows to serve static content from <code>public</code>, so you don't need to use <code>Rack::Static</code>.
|
|
74
97
|
|
|
75
98
|
## Author
|
|
76
99
|
|
data/bin/hyper
CHANGED
|
@@ -6,15 +6,20 @@ options = {}
|
|
|
6
6
|
parser = OptionParser.new do |opts|
|
|
7
7
|
opts.banner = "Usage: hyper new NAME [options]"
|
|
8
8
|
|
|
9
|
-
opts.on('-f', '--force', 'Overwrite existing files') do
|
|
9
|
+
opts.on('-f', '--force', '# Overwrite existing files') do
|
|
10
10
|
options[:force] = true
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
opts.on('-v', '--version', '# Show version and exit') do
|
|
14
|
+
puts "Hyper #{Hyper::Version.to_s}"; exit
|
|
15
|
+
end
|
|
12
16
|
end
|
|
13
17
|
|
|
18
|
+
parser.parse!
|
|
19
|
+
|
|
14
20
|
case ARGV.first
|
|
15
21
|
when 'new'
|
|
16
22
|
if name = ARGV[1]
|
|
17
|
-
parser.parse!
|
|
18
23
|
Hyper::Generator.new(name, options).generate
|
|
19
24
|
else
|
|
20
25
|
puts "Please provide a name"
|
data/lib/hyper.rb
CHANGED
|
@@ -1,30 +1,35 @@
|
|
|
1
1
|
require 'rack/builder'
|
|
2
2
|
|
|
3
3
|
module Hyper
|
|
4
|
-
autoload :
|
|
5
|
-
autoload :
|
|
6
|
-
autoload :Static,
|
|
7
|
-
autoload :Utils,
|
|
8
|
-
autoload :Version,
|
|
4
|
+
autoload :Application, 'hyper/application'
|
|
5
|
+
autoload :Generator, 'hyper/generator'
|
|
6
|
+
autoload :Static, 'hyper/static'
|
|
7
|
+
autoload :Utils, 'hyper/utils'
|
|
8
|
+
autoload :Version, 'hyper/version'
|
|
9
9
|
|
|
10
10
|
extend self
|
|
11
11
|
|
|
12
|
-
# @api public
|
|
13
12
|
def call(env)
|
|
14
13
|
builder = Rack::Builder.new do
|
|
15
14
|
use Hyper::Static
|
|
16
|
-
run Hyper::
|
|
15
|
+
run Hyper::Application.new
|
|
17
16
|
end
|
|
18
17
|
|
|
19
18
|
builder.to_app.call(env)
|
|
20
19
|
end
|
|
21
20
|
|
|
22
|
-
# @api public
|
|
23
21
|
def root
|
|
24
|
-
Pathname.new(Dir.pwd)
|
|
22
|
+
@root ||= Pathname.new(Dir.pwd)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def root=(path)
|
|
26
|
+
@root = Pathname.new(path)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def template_root
|
|
30
|
+
@template_root ||= root.join('templates')
|
|
25
31
|
end
|
|
26
32
|
|
|
27
|
-
# @api public
|
|
28
33
|
def template_root=(path)
|
|
29
34
|
@template_root = Pathname.new(path)
|
|
30
35
|
end
|
|
@@ -32,9 +37,4 @@ module Hyper
|
|
|
32
37
|
def view_root
|
|
33
38
|
@view_root ||= template_root.join('views')
|
|
34
39
|
end
|
|
35
|
-
|
|
36
|
-
# @api private
|
|
37
|
-
def template_root
|
|
38
|
-
@template_root ||= root.join('templates')
|
|
39
|
-
end
|
|
40
40
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'rack/request'
|
|
2
|
+
require 'tilt'
|
|
3
|
+
require Hyper.root.join('lib/helper')
|
|
4
|
+
|
|
5
|
+
module Hyper
|
|
6
|
+
class Application
|
|
7
|
+
include Hyper::Helper
|
|
8
|
+
|
|
9
|
+
attr :request
|
|
10
|
+
|
|
11
|
+
def call(env)
|
|
12
|
+
@request = Rack::Request.new(env)
|
|
13
|
+
url = request.path
|
|
14
|
+
layout = Utils.layout_path
|
|
15
|
+
view = Utils.view_path(url)
|
|
16
|
+
|
|
17
|
+
if File.file?(view)
|
|
18
|
+
respond_with(200, rendered_templates(layout, view))
|
|
19
|
+
else
|
|
20
|
+
respond_with(404, "404 Not Found: #{url}")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
def respond_with(status, body)
|
|
26
|
+
[status, headers_for(body), StringIO.new(body)]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def headers_for(body)
|
|
30
|
+
{'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def rendered_templates(layout, view)
|
|
34
|
+
render_erb(layout) { render_erb(view) }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def render_erb(template, &block)
|
|
38
|
+
Tilt.new(template, :trim => '-').render(self, &block)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/hyper/generator.rb
CHANGED
data/lib/hyper/static.rb
CHANGED
data/lib/hyper/utils.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
module Hyper
|
|
2
|
-
# @api private
|
|
3
2
|
module Utils
|
|
4
3
|
extend self
|
|
5
4
|
|
|
@@ -25,7 +24,7 @@ module Hyper
|
|
|
25
24
|
if ['', '/'].include?(url) # Root URL
|
|
26
25
|
'/index'
|
|
27
26
|
elsif url =~ /.+\/$/ # Folder indexes
|
|
28
|
-
|
|
27
|
+
url + 'index'
|
|
29
28
|
else # Everything else
|
|
30
29
|
url
|
|
31
30
|
end
|
data/lib/hyper/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hyper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
5
|
-
prerelease:
|
|
4
|
+
hash: 19
|
|
5
|
+
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 3
|
|
9
9
|
- 0
|
|
10
|
-
|
|
11
|
-
- 1
|
|
12
|
-
version: 0.3.0beta1
|
|
10
|
+
version: 0.3.0
|
|
13
11
|
platform: ruby
|
|
14
12
|
authors:
|
|
15
13
|
- James Wilding
|
|
@@ -17,7 +15,7 @@ autorequire:
|
|
|
17
15
|
bindir: bin
|
|
18
16
|
cert_chain: []
|
|
19
17
|
|
|
20
|
-
date: 2011-
|
|
18
|
+
date: 2011-07-07 00:00:00 +01:00
|
|
21
19
|
default_executable:
|
|
22
20
|
dependencies:
|
|
23
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -89,8 +87,8 @@ extensions: []
|
|
|
89
87
|
extra_rdoc_files: []
|
|
90
88
|
|
|
91
89
|
files:
|
|
90
|
+
- lib/hyper/application.rb
|
|
92
91
|
- lib/hyper/generator.rb
|
|
93
|
-
- lib/hyper/response.rb
|
|
94
92
|
- lib/hyper/static.rb
|
|
95
93
|
- lib/hyper/template/config.ru
|
|
96
94
|
- lib/hyper/template/Gemfile
|
|
@@ -122,14 +120,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
122
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
121
|
none: false
|
|
124
122
|
requirements:
|
|
125
|
-
- - "
|
|
123
|
+
- - ">="
|
|
126
124
|
- !ruby/object:Gem::Version
|
|
127
|
-
hash:
|
|
125
|
+
hash: 3
|
|
128
126
|
segments:
|
|
129
|
-
-
|
|
130
|
-
|
|
131
|
-
- 1
|
|
132
|
-
version: 1.3.1
|
|
127
|
+
- 0
|
|
128
|
+
version: "0"
|
|
133
129
|
requirements: []
|
|
134
130
|
|
|
135
131
|
rubyforge_project:
|
data/lib/hyper/response.rb
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
require 'rack/request'
|
|
2
|
-
require 'tilt'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module Hyper
|
|
6
|
-
# @api private
|
|
7
|
-
class Response
|
|
8
|
-
def call(env)
|
|
9
|
-
request = Rack::Request.new(env)
|
|
10
|
-
headers = {'Content-Type' => 'text/html'}
|
|
11
|
-
layout = Utils.layout_path
|
|
12
|
-
view = Utils.view_path(request.path)
|
|
13
|
-
|
|
14
|
-
if File.file?(view)
|
|
15
|
-
status = 200
|
|
16
|
-
body = render_templates(layout, view)
|
|
17
|
-
else
|
|
18
|
-
status = 404
|
|
19
|
-
body = "404 Not Found: #{request.path}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
[status, headers, StringIO.new(body)]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
def render_templates(layout, view)
|
|
27
|
-
render_erb(layout) { render_erb(view) }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def render_erb(template, &block)
|
|
31
|
-
Tilt.new(template, :trim => '-').render(&block)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|