simplerb 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/README.md +52 -0
- data/lib/simplerb.rb +9 -3
- data/lib/simplerb/cli.rb +1 -2
- data/lib/simplerb/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46c7ce1b03cdef23e4ee698a85f86c12f457093d
|
4
|
+
data.tar.gz: a4239b86260c53d388695b601541329095d879d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b8c1a7343b42977c5f86bf8639a641c0e5c9b3bbec7e6527df0e4229492e4f2e8b1fdad394301af32464b1f9fd2d37ce6f4a61ca092b2d1d5de1b3f9fc9cdb6
|
7
|
+
data.tar.gz: d9993023779de032c5b1fa17e74d839c115c84baa80f839edcd65565fb6f50b68fe2a7cf99e7deb68f95a3090b1ad7fbaa54f45f94bdb068ab8337ba874d3db6
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Simplerb
|
2
|
+
|
3
|
+
A super simple framework for creating dynamic websites with Ruby and ERB.
|
4
|
+
Basically PHP-style web development in Ruby. The main purpose is to teach web
|
5
|
+
development to beginners.
|
6
|
+
|
7
|
+
|
8
|
+
# Installation
|
9
|
+
|
10
|
+
Just install the gem by running `gem install simplerb`
|
11
|
+
|
12
|
+
|
13
|
+
# Getting Started
|
14
|
+
|
15
|
+
To create a new project called `hello_world`, run this from the console:
|
16
|
+
|
17
|
+
```
|
18
|
+
simplerb new hello_world
|
19
|
+
```
|
20
|
+
|
21
|
+
This will create a directory called `hello_world` with some files and
|
22
|
+
subdirectories in it:
|
23
|
+
|
24
|
+
```
|
25
|
+
- hello_world
|
26
|
+
\_ views
|
27
|
+
|_ public
|
28
|
+
|_ config.ru
|
29
|
+
```
|
30
|
+
|
31
|
+
Now you can start the server by running `simplerb server`. Open your browser and
|
32
|
+
visit `http://localhost:9292`: if everything is up and running you should now
|
33
|
+
see a page with some greetings.
|
34
|
+
|
35
|
+
|
36
|
+
# Adding pages
|
37
|
+
|
38
|
+
You can add pages by creating `erb` files in the `views` directory. For example,
|
39
|
+
try creating a file `views/hello.erb` containing the text "Hello, World!". Now,
|
40
|
+
if you visit `http://localhost:9292/hello`, you should see that text.
|
41
|
+
|
42
|
+
If you want to reuse a part of a page (a "partial") in multiple pages, just
|
43
|
+
extract it into a separate file with a name starting with an underscore (e.g.
|
44
|
+
`_my_shared_content`). Then, within a page, call `<%= partial 'my_shared_content' %>`
|
45
|
+
to render the partial.
|
46
|
+
|
47
|
+
|
48
|
+
# Static files
|
49
|
+
|
50
|
+
Any static file that you put in the `public` folder will be served at the
|
51
|
+
corresponding URL, so if you create a file `public/styles/my_style.css`,
|
52
|
+
it will be served at `http://localhost:9292/styles/my_style.css`.
|
data/lib/simplerb.rb
CHANGED
@@ -8,7 +8,7 @@ module Simplerb
|
|
8
8
|
send verb.to_sym, '/*' do
|
9
9
|
path = params[:splat].first
|
10
10
|
views = view_files('[^_]*.erb')
|
11
|
-
if views.include? File.join(settings.views, "#{path}.erb")
|
11
|
+
if views.include? File.join(settings.views, "#{path}.erb")
|
12
12
|
erb path.to_sym
|
13
13
|
elsif views.include? File.join(settings.views, path, 'index.erb')
|
14
14
|
erb File.join(path, 'index').to_sym
|
@@ -24,8 +24,14 @@ module Simplerb
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def partial(partial)
|
27
|
-
|
28
|
-
|
27
|
+
# Put underscore in last path component
|
28
|
+
file_path = partial.gsub(/(.*)\//, '\1/_')
|
29
|
+
full_path = File.join(settings.views, "#{file_path}.erb")
|
30
|
+
|
31
|
+
if view_files('_*.erb').include? full_path
|
32
|
+
erb file_path.to_sym, layout: false
|
33
|
+
else
|
34
|
+
raise "Couldn't find partial '#{partial}' at path '#{full_path}'"
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
data/lib/simplerb/cli.rb
CHANGED
@@ -24,8 +24,7 @@ module Simplerb
|
|
24
24
|
option :port, desc: 'specify the port', type: :numeric, default: 9292, aliases: [:p]
|
25
25
|
option :server, desc: 'specify the webserver', type: :string, default: 'webrick', aliases: [:s]
|
26
26
|
def server
|
27
|
-
|
28
|
-
rescue Interrupt
|
27
|
+
exec "rackup -p #{options[:port]} -s #{options[:server]}"
|
29
28
|
end
|
30
29
|
|
31
30
|
def self.source_root
|
data/lib/simplerb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplerb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Ongaro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -62,6 +62,7 @@ executables:
|
|
62
62
|
extensions: []
|
63
63
|
extra_rdoc_files: []
|
64
64
|
files:
|
65
|
+
- README.md
|
65
66
|
- bin/simplerb
|
66
67
|
- lib/simplerb.rb
|
67
68
|
- lib/simplerb/cli.rb
|