syro 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -0
  3. data/lib/syro.rb +5 -4
  4. data/syro.gemspec +1 -1
  5. data/test/all.rb +25 -1
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 024518f1cb6e65935ea456dc18ac359d1b18eae4
4
- data.tar.gz: 8834daf0ca51401e82b0fe1cd05fb2f71986a5ca
3
+ metadata.gz: 76dac1dc767f0ca11941aba2e7e9ebb44a19dd0f
4
+ data.tar.gz: 1857b66de5723f4cd08832bf8dedb5b6c089044c
5
5
  SHA512:
6
- metadata.gz: b5fc9a10dbc89d25bc24b75ab697c03d9f6bb4407daa07505c3967c8b762074ec1769d34f802c39cd37c2f5deb21f9f8a33e0e7b8d3eeb3c22e432e0d45a1a9f
7
- data.tar.gz: 586fadba5f72bcec32fb1f5498f4a15f2a655bfb5dbed9a4b9f7b7702f5272f8e64de76cbb8d34347d5a09c626236900b6f4817d68f7db7ca779197630566225
6
+ metadata.gz: 18dba2a7313b529be3dcf7572070a842bf9d389b4878d788d19003b384a7f6548ea6ae45d098c63ef26ce5b7d9da1833d9ba7edf0249047c7d523af7f032c9fa
7
+ data.tar.gz: 0cd2379ff3ac4edebaca98a1644bf985ebeb187c5aec2f0a5a77e3336ed83c63f4dc43d9f1189d174b3a3199b5f1b9dd8596b7a5dfa2bd1f1fee0585c524cabd
data/README.md CHANGED
@@ -89,6 +89,37 @@ are true.
89
89
  `delete`: Receives a block and calls it only if `root?` and `req.delete?`
90
90
  are true.
91
91
 
92
+ Decks
93
+ -----
94
+
95
+ The sandbox where the application is evaluated is an instance of
96
+ `Syro::Deck`, and it provides the API described earlier. You can
97
+ define your own `Deck` and pass it to the `Syro` constructor. All
98
+ the methods defined in there will be accessible from your routes.
99
+ Here's an example:
100
+
101
+ ```ruby
102
+ class TextualDeck < Syro::Deck
103
+ def text(str)
104
+ res[Rack::CONTENT_TYPE] = "text/plain"
105
+ res.write(str)
106
+ end
107
+ end
108
+
109
+ App = Syro.new(TextualDeck) {
110
+ get {
111
+ text("hello world")
112
+ }
113
+ }
114
+ ```
115
+
116
+ The example is simple enough to showcase the concept, but maybe too
117
+ simple to be meaningful. The idea is that you can create your own
118
+ specialized decks and reuse them in different applications. You can
119
+ also define modules and later include them in your decks: for
120
+ example, you can write modules for rendering or serializing data,
121
+ and then you can combine those modules in your custom decks.
122
+
92
123
  Examples
93
124
  --------
94
125
 
@@ -83,7 +83,7 @@ class Syro
83
83
  end
84
84
  end
85
85
 
86
- class Sandbox
86
+ class Deck
87
87
  def initialize(code)
88
88
  @syro_code = code
89
89
  end
@@ -195,11 +195,12 @@ class Syro
195
195
  end
196
196
  end
197
197
 
198
- def initialize(&block)
199
- @code = block
198
+ def initialize(deck = Deck, &code)
199
+ @deck = deck
200
+ @code = code
200
201
  end
201
202
 
202
203
  def call(env, inbox = {})
203
- Sandbox.new(@code).call(env, inbox)
204
+ @deck.new(@code).call(env, inbox)
204
205
  end
205
206
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "syro"
3
- s.version = "0.0.3"
3
+ s.version = "0.0.4"
4
4
  s.summary = "Simple router"
5
5
  s.description = "Simple router for web applications"
6
6
  s.authors = ["Michel Martens"]
@@ -1,6 +1,19 @@
1
+ class TextualDeck < Syro::Deck
2
+ def text(str)
3
+ res[Rack::CONTENT_TYPE] = "text/plain"
4
+ res.write(str)
5
+ end
6
+ end
7
+
8
+ textual = Syro.new(TextualDeck) {
9
+ get {
10
+ text("GET /textual")
11
+ }
12
+ }
13
+
1
14
  admin = Syro.new {
2
15
  get {
3
- res.write "GET /admin"
16
+ res.write("GET /admin")
4
17
  }
5
18
  }
6
19
 
@@ -106,6 +119,10 @@ app = Syro.new {
106
119
  res.redirect("/one")
107
120
  }
108
121
  }
122
+
123
+ on("textual") {
124
+ run(textual)
125
+ }
109
126
  }
110
127
 
111
128
  setup do
@@ -194,3 +211,10 @@ test "redirect" do |f|
194
211
  assert_equal "1", f.last_response.body
195
212
  assert_equal 200, f.last_response.status
196
213
  end
214
+
215
+ test "custom deck" do |f|
216
+ f.get("/textual")
217
+ assert_equal "GET /textual", f.last_response.body
218
+ assert_equal "text/plain", f.last_response.headers["Content-Type"]
219
+ assert_equal 200, f.last_response.status
220
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-27 00:00:00.000000000 Z
11
+ date: 2015-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: seg