simplerb 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d63903a64cc0f99c63825674f533ceb919632d0a
4
+ data.tar.gz: 4c2206290324359ae62237dfe82a0c3628e88d8a
5
+ SHA512:
6
+ metadata.gz: d0fe75aed70c0b085a98e49878881d25031254cb8e88e5c2e9517454ed2879db0bd8764fc4d9605d67ccfad7447f3290a768da47145b6dc50df672bbafe02cb6
7
+ data.tar.gz: 7078da807ba1767bb0224c0ef210b4fb089b23496f97e1fd0a9d06af5cb9f0c7c76d0a8758af202771cb999ee0af997cbdcdc97683ac8201defe20226a715a5a
data/bin/simplerb ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'simplerb/cli'
4
+ Simplerb::CLI.start(ARGV)
@@ -0,0 +1,29 @@
1
+ require 'thor'
2
+ require 'thor/actions'
3
+
4
+ module Simplerb
5
+ class CLI < Thor
6
+ include Thor::Actions
7
+
8
+ desc 'new NAME', 'create a new Simplerb project called NAME'
9
+ def new(name)
10
+ self.destination_root = Pathname.pwd.join(name)
11
+ options = { name: name }
12
+ directory('views', options)
13
+ directory('public', options)
14
+ template('config.ru.tt', options)
15
+ end
16
+
17
+ desc 'server', 'start a local server'
18
+ option :port, desc: 'specify the port', type: :numeric, default: 9292, aliases: [:p]
19
+ option :server, desc: 'specify the webserver', type: :string, default: 'webrick', aliases: [:s]
20
+ def server
21
+ system "rackup -p #{options[:port]} -s #{options[:server]}"
22
+ rescue Interrupt
23
+ end
24
+
25
+ def self.source_root
26
+ File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ require 'simplerb'
2
+ <% class_name = config[:name].split(/[_\-\s]+/).map(&:capitalize).join %>
3
+
4
+ class <%= class_name %> < Simplerb::Base
5
+ set views: 'views', public_folder: 'public'
6
+
7
+ # To add your custom settings:
8
+ # set foo: 'bar'
9
+
10
+ # To add your custom helpers:
11
+ # helpers do
12
+ # def say_hello
13
+ # 'hello'
14
+ # end
15
+ # end
16
+ end
17
+
18
+ run <%= class_name %>
@@ -0,0 +1,6 @@
1
+ body {
2
+ background-color: #CCEEFF;
3
+ color: #333333;
4
+ font-family: Helvetica, Arial, 'sans-serif';
5
+ text-align: center;
6
+ }
@@ -0,0 +1,3 @@
1
+ <h1>Welcome to Simplerb!</h1>
2
+
3
+ Have fun making websites ;)
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= config[:name] %></title>
5
+ <link rel='stylesheet' type='text/css' media='all' href='application.css'>
6
+ </head>
7
+ <body>
8
+ <%%= yield %>
9
+ </body>
10
+ </html>
@@ -0,0 +1,3 @@
1
+ module Simplerb
2
+ VERSION = '0.0.1'
3
+ end
data/lib/simplerb.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'sinatra/base'
2
+
3
+ module Simplerb
4
+ class Base < Sinatra::Base
5
+ HTTP_VERBS = ['get', 'post', 'put', 'patch', 'delete']
6
+
7
+ HTTP_VERBS.each do |verb|
8
+ send verb.to_sym, '/*' do
9
+ path = params[:splat].first
10
+ views = view_files('[^_]*.erb')
11
+ if views.include? File.join(settings.views, "#{path}.erb")
12
+ erb path.to_sym
13
+ elsif views.include? File.join(settings.views, path, 'index.erb')
14
+ erb File.join(path, 'index').to_sym
15
+ else
16
+ pass
17
+ end
18
+ end
19
+ end
20
+
21
+ helpers do
22
+ def view_files(pattern = '*')
23
+ Dir.glob(File.join(settings.views, '**', pattern))
24
+ end
25
+
26
+ def partial(partial)
27
+ if view_files('_*.erb').include? File.join(settings.views, "_#{partial}.erb")
28
+ erb "_#{partial}".to_sym, layout: false
29
+ end
30
+ end
31
+
32
+ HTTP_VERBS.each do |verb|
33
+ define_method "http_#{verb}?" do
34
+ request.request_method == verb.upcase
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplerb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Luca Ongaro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Simplerb is a super simple and minimal framework for generating dynamic
42
+ websites "PHP-style" but with Ruby and ERB. Its main purpose is to help teaching
43
+ web development to beginners.
44
+ email:
45
+ - lukeongaro@gmail.com
46
+ executables:
47
+ - simplerb
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - bin/simplerb
52
+ - lib/simplerb.rb
53
+ - lib/simplerb/cli.rb
54
+ - lib/simplerb/templates/config.ru.tt
55
+ - lib/simplerb/templates/public/application.css.tt
56
+ - lib/simplerb/templates/views/index.erb.tt
57
+ - lib/simplerb/templates/views/layout.erb.tt
58
+ - lib/simplerb/version.rb
59
+ homepage:
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 1.9.2
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: A super simple dynamic website framework for educational purpose
83
+ test_files: []