salen 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: 21ad2fba738f9fd719a922e2a0c74dcfde3b2a1f
4
+ data.tar.gz: 733b35a7b1e3c139ca922a32cc0bd90517bffc05
5
+ SHA512:
6
+ metadata.gz: 7dff29bdf769015afce5c5e451c25604f0d01bbfac5538e9789224a726ee7a2d4e898cf5fa47a14455361f56bc1f1b48f3a37502fb55590aa57ae3f317cdf490
7
+ data.tar.gz: b350770b6dfc6f0abfe70dc4d4e1756e31d845b505f70d009bd7a419005e37fc968641ce665a73c1e7edb460acf17f9cb4ebbaaa91e8f949967772f4bda48964
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in salen.gemspec
4
+ gem 'rack'
5
+ gem 'pry'
6
+ gem 'pry-debugger'
7
+
8
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kyuden
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Salen
2
+
3
+ Salen is a small and callow web application framework in Ruby.
4
+
5
+ ```ruby
6
+ require 'salen'
7
+
8
+ class SampleApp < Salen::App
9
+ get '/' do
10
+ 'Hello Salen'
11
+ end
12
+ end
13
+
14
+ SampleApp.run!
15
+ ```
16
+
17
+ And run with:
18
+
19
+ ```
20
+ ruby sample_app.rb
21
+ ```
22
+
23
+ View at: http://localhost:8080
24
+
25
+ ## Installation
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ gem 'salen'
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install salen
38
+
39
+ ## Routes
40
+
41
+ In Salen, a route is an HTTP method paired with a URL-matching pattern. Each route is associated with a block:
42
+
43
+ ```ruby
44
+ get '/' do
45
+ .. show something ..
46
+ end
47
+ ```
48
+
49
+ Route patterns may include named parameters, accessible via the params hash:
50
+ ```ruby
51
+ get '/hello/:name' do
52
+ # matches "GET /hello/foo" and "GET /hello/bar"
53
+ # params[:name] is 'foo' or 'bar'
54
+ "Hello #{params[:name]}!"
55
+ end
56
+ ```
57
+ ### Browser Redirect
58
+
59
+ You can trigger a browser redirect with the redirect helper method:
60
+
61
+ ```ruby
62
+ get '/hello' do
63
+ redirect_to "/"
64
+ end
65
+ ```
66
+
67
+ ## Views / Templates
68
+
69
+ Default template is haml
70
+
71
+ ```ruby
72
+ get '/hello' do
73
+ haml 'index'
74
+ end
75
+ ```
76
+
77
+
78
+
79
+
80
+ ## Contributing
81
+
82
+ 1. Fork it ( https://github.com/[my-github-username]/salen/fork )
83
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
84
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
85
+ 4. Push to the branch (`git push origin my-new-feature`)
86
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/bin/salen ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'salen'
@@ -0,0 +1,21 @@
1
+ require 'salen'
2
+
3
+ class SampleApp < Salen::App
4
+ get '/' do
5
+ 'Hello world'
6
+ end
7
+
8
+ get '/kyuden' do
9
+ redirect_to "/"
10
+ end
11
+
12
+ get '/recipe' do
13
+ haml 'index'
14
+ end
15
+
16
+ get '/hello/:name' do
17
+ params[:name]
18
+ end
19
+ end
20
+
21
+ SampleApp.run!
@@ -0,0 +1,153 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{charset: "UTF-8"}/
5
+ %title カレーのレシピ
6
+ %body
7
+ %article
8
+ %header
9
+ %h1 カレーのレシピ
10
+ %section
11
+ %p
12
+ 誰でもできる、美味しいカレーの作り方です。旦那も息子もこのカレーが大好物。
13
+ %br/
14
+ ポイントは玉ねぎと人参はミキサーで細かくしてしまうところ。逆にコクのある美味しいカレーになります。
15
+ %p
16
+ レシピの作者
17
+ %br/
18
+ 山田サチ子さん
19
+ %header
20
+ %h2 材料 ( 8皿分 )
21
+ %section
22
+ %table
23
+ %tr
24
+ %td 豚肉(薄切り)
25
+ %td 300g
26
+ %tr
27
+ %td じゃがいも(中)
28
+ %td 4個
29
+ %tr
30
+ %td ☆玉ねぎ
31
+ %td 2個
32
+ %tr
33
+ %td ☆人参(中)
34
+ %td 1本半
35
+ %tr
36
+ %td ☆にんにく
37
+ %td 2個
38
+ %tr
39
+ %td ローリエ
40
+ %td 2枚
41
+ %tr
42
+ %td 市販のカレー粉(2種類合わせて)
43
+ %td 1箱分
44
+ %header
45
+ %h3 調味料
46
+ %section
47
+ %table
48
+ %tr
49
+ %td ガラムマサラ
50
+ %td 大2
51
+ %tr
52
+ %td こしょう
53
+ %td 小1
54
+ %tr
55
+ %td ハチミツ
56
+ %td 大4
57
+ %tr
58
+ %td 中濃ソース
59
+ %td 大1
60
+ %header
61
+ %h2 作り方
62
+ %section
63
+ %ol
64
+ %li
65
+ 材料を準備。
66
+ %br/
67
+ 今回カレー粉
68
+ %br/
69
+ ジャワカレー辛口×こくまろカレー中辛
70
+ %br/
71
+ %li
72
+ ☆を2回に分けてフードプロセッサーにかけます。
73
+ %br/
74
+ (人参だけだと、水分が出ないので必ず玉ねぎと一緒に)
75
+ %br/
76
+ %li
77
+ ジャガイモは角をとっておきます。
78
+ %br/
79
+ (省略可能)
80
+ %br/
81
+ %li
82
+ 油をしいた鍋で豚肉を炒めます。
83
+ %br/
84
+ 少し白くなってきたら、塩コショウをして炒め、更にお酒を加えて水気がなくなるまで炒めます。
85
+ %br/
86
+ %li
87
+ 鍋に2.を加え少し色が変わってきたら塩コショウします。
88
+ %br/
89
+ %li
90
+ 水分がある程度飛ぶまで炒めます。
91
+ %br/
92
+ (結構時間がかかります)
93
+ %br/
94
+ %li
95
+ そこに3.のジャガイモを取った角ごと入れ、簡単に火を通します。
96
+ %br/
97
+ %li
98
+ 水を加えます。ついでに、フードプロセッサーもキレイに!
99
+ %br/
100
+ %li
101
+ 鍋に水とローリエを加え焦げないよう、たまにかき混ぜながら20〜30分中火→弱火で煮ます。
102
+ %br/
103
+ %li
104
+ 火を止めてカレールウを入れて混ぜ、再度火をつけます。
105
+ %br/
106
+ (底が焦げ易いので、マメにかき混ぜて下さい)
107
+ %br/
108
+ %li
109
+ 10分位煮立て、更に●を入れて10分位煮込みます。
110
+ %br/
111
+ %strong ※こしょうは最初少なめに入れ、辛さ調整しながら徐々に足していきます。
112
+ %br/
113
+ %li
114
+ 味が整ったら火を消し完成。
115
+ %br/
116
+ %strong ※この時点で多少スパイスがキツくても、置いておけばマイルドになっているので大丈夫です!
117
+ %br/
118
+ %li
119
+ 食べる前に再度火を通せばOK!
120
+ %br/
121
+ スパイスの効いた辛さの中に甘みのあるカレーです!
122
+ %br/
123
+ 残った具は肉と小さなジャガイモのみ。
124
+ %br/
125
+ 野菜嫌いでも快く食べられます!
126
+ %header
127
+ %h2 ポイント
128
+ %section
129
+ %p
130
+ 甘さと辛さの調節はコショウとハチミツで!コショウで辛口に、ハチミツで甘さとコクを出します。
131
+ %br/
132
+ 焦げやすいので、まめにかき混ぜて下さい。ルウを入れた後はお水を足しながら緩さ調整して下さい。
133
+ %br/
134
+ あればりんご1/3を、2.に投入して下さい。
135
+ %header
136
+ %h2 このレシピの生い立ち
137
+ %section
138
+ %p
139
+ 野菜嫌いなる主人、息子に野菜を食べてもらおうと、
140
+ %br/
141
+ 玉ねぎと人参はフードプロセッサーにかけ除けられないようにしたところ、これが我が家のカレーの定番になりました。
142
+ %header
143
+ %h2 コメント
144
+ %section
145
+ %blockquote
146
+ うちでも試してみました。とても美味しかったです。ありがとうございます。
147
+ %br/
148
+ 投稿者 岩鬼正美さん
149
+ %br/
150
+ %br/
151
+ うちの息子も野菜嫌いなのですが、このカレーは美味しく何度もおかわりしてました。
152
+ %br/
153
+ 投稿者 殿馬数人
data/lib/salen.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'salen/version'
2
+ require 'salen/app'
data/lib/salen/app.rb ADDED
@@ -0,0 +1,99 @@
1
+ require 'rack'
2
+ require 'tilt'
3
+
4
+ module Salen
5
+ class App
6
+ HTTP_VERBS = %i(get post)
7
+
8
+ def call env
9
+ request = Request.new env
10
+ response = Response.new request.body(self.class), request.status, request.headers
11
+ response.finish
12
+ end
13
+
14
+ class << self
15
+ def routes
16
+ @routes ||= Hash.new {|h,k| h[k] = Hash.new(&h.default_proc) }
17
+ end
18
+
19
+ HTTP_VERBS.each do |method|
20
+ define_method method do |path, &block|
21
+ routes[method][path] = Proc.new &block
22
+ end
23
+ end
24
+
25
+ def run!
26
+ app = new
27
+ builder =
28
+ Rack::Builder.new do
29
+ run app
30
+ use Rack::ShowExceptions
31
+ use Rack::CommonLogger
32
+ use Rack::Lint
33
+ end
34
+
35
+ Rack::Handler::WEBrick.run builder
36
+ end
37
+ end
38
+ end
39
+
40
+ class Request < Rack::Request
41
+ attr_accessor :headers, :status, :params, :route_body
42
+
43
+ def initialize env
44
+ @headers = {'Content-Type' => 'text/html'}
45
+ @status = 200
46
+ super env
47
+ end
48
+
49
+ def redirect_to uri
50
+ @headers = { "Location" => uri }
51
+ @status = 301
52
+ end
53
+
54
+ def haml template
55
+ render :haml, template_path(template, '.html.haml')
56
+ end
57
+
58
+ def template_path template, extention
59
+ File.join('views', template + extention)
60
+ end
61
+
62
+ def render engin, template
63
+ Tilt.new(template).render
64
+ end
65
+
66
+ def body app_class
67
+ dispatch_route(app_class.routes.fetch(request_method.downcase.to_sym), path)
68
+ [instance_eval(&route_body.last).to_s]
69
+ end
70
+
71
+ private
72
+
73
+ def dispatch_route routes, path
74
+ @params = Hash[params_values(routes).zip(params_keys)].invert
75
+ end
76
+
77
+ def params_keys
78
+ keys = []
79
+ route_body.first.gsub %r<:([^/])+> do |k,v|
80
+ keys.push k.delete!(':').to_sym
81
+ end
82
+ keys
83
+ end
84
+
85
+ def params_values routes
86
+ vals = []
87
+ @route_body =
88
+ routes.detect do |k,v|
89
+ path.match Regexp.new("^"+k.gsub(%r<:([^/])+>, "([^/])+")+"$") do |md|
90
+ vals = md[1..-1]
91
+ end
92
+ end
93
+ vals
94
+ end
95
+ end
96
+
97
+ class Response < Rack::Response
98
+ end
99
+ end
@@ -0,0 +1,3 @@
1
+ module Salen
2
+ VERSION = "0.0.1"
3
+ end
data/salen.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'salen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "salen"
8
+ spec.version = Salen::VERSION
9
+ spec.authors = ["Kyuden"]
10
+ spec.email = ["msmsms.um@gmail.com"]
11
+ spec.summary = %q{Write a short summary. Required.}
12
+ spec.description = %q{Write a longer description. Optional.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "tilt"
22
+ spec.add_dependency "haml"
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Salen do
4
+ it 'has a version number' do
5
+ expect(Salen::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'salen'
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: salen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kyuden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tilt
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: haml
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
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Write a longer description. Optional.
84
+ email:
85
+ - msmsms.um@gmail.com
86
+ executables:
87
+ - salen
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/salen
99
+ - examples/sample_app.rb
100
+ - examples/views/index.html.haml
101
+ - lib/salen.rb
102
+ - lib/salen/app.rb
103
+ - lib/salen/version.rb
104
+ - salen.gemspec
105
+ - spec/salen_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: ''
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.2.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Write a short summary. Required.
131
+ test_files:
132
+ - spec/salen_spec.rb
133
+ - spec/spec_helper.rb