rack-component 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.reek.yml +4 -0
- data/.travis.yml +0 -1
- data/Gemfile.lock +1 -1
- data/README.md +28 -1
- data/lib/rack/component.rb +10 -0
- data/lib/rack/component/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5f073b2ec6adad102c5fb898e7071c7531663960f6188c678a1b46c7f564e2f
|
4
|
+
data.tar.gz: f0bbc1b2c7cee8fca01ec2f7e0d75b0ca260428e24a50ec6f28a9a70e714b6f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdfd59e87eccbc6cc0be4a92579813d76195d14e0cfb3620f6ec3a3204730cb8ba35f528d59e260db268bb2a697acb1bb6ccf3c8615fbb52979aa67e15e91858
|
7
|
+
data.tar.gz: 76ab042215b76839bab82c36ac19682da07050ed0da54d714ffc6e609160ef360962e445b4ef9f71ade86e35ff2dc65668ace167880c92203c4da565f4d09036
|
data/.reek.yml
CHANGED
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Rack::Component
|
2
2
|
|
3
3
|
Like a React.js component, a `Rack::Component` implements a `render` method that
|
4
|
-
takes input data and returns what to display.
|
4
|
+
takes input data and returns what to display. You can use Components instead of
|
5
|
+
Controllers, Views, Templates, and Helpers, in any Rack app.
|
5
6
|
|
6
7
|
## Install
|
7
8
|
|
@@ -11,6 +12,32 @@ Add `rack-component` to your Gemfile and run `bundle install`:
|
|
11
12
|
gem 'rack-component'
|
12
13
|
```
|
13
14
|
|
15
|
+
## Quickstart with Sinatra
|
16
|
+
```ruby
|
17
|
+
# config.ru
|
18
|
+
require 'sinatra'
|
19
|
+
require 'rack/component'
|
20
|
+
|
21
|
+
class Hello < Rack::Component
|
22
|
+
render do |env|
|
23
|
+
"<h1>Hello, #{h(env[:name])}</h1>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
get '/hello/:name' do
|
28
|
+
Hello.call(name: params[:name])
|
29
|
+
end
|
30
|
+
|
31
|
+
run Sinatra::Application
|
32
|
+
```
|
33
|
+
|
34
|
+
**Note that Rack::Component currently does not escape strings by default**. To
|
35
|
+
escape strings, you must use the `#h` helper, as in the example above.
|
36
|
+
|
37
|
+
There is an [issue open](https://github.com/chrisfrank/rack-component/issues/4)
|
38
|
+
to discuss how to enable escaping by default. If you have ideas or opinions, I'd
|
39
|
+
love to hear about them there.
|
40
|
+
|
14
41
|
## Table of Contents
|
15
42
|
|
16
43
|
* [Getting Started](#getting-started)
|
data/lib/rack/component.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'component/version'
|
2
2
|
require_relative 'component/memory_cache'
|
3
|
+
require 'cgi'
|
3
4
|
|
4
5
|
module Rack
|
5
6
|
# Subclass Rack::Component to compose functional, declarative responses to
|
@@ -117,5 +118,14 @@ module Rack
|
|
117
118
|
end
|
118
119
|
|
119
120
|
attr_reader :env
|
121
|
+
|
122
|
+
# @example Strip HTML entities from a string
|
123
|
+
# class SafeComponent < Rack::Component
|
124
|
+
# render { |env| h(env[:name]) }
|
125
|
+
# end
|
126
|
+
# SafeComponent.call(name: '<h1>hi</h1>') #=> <h1>hi</h1>
|
127
|
+
def h(obj)
|
128
|
+
CGI.escapeHTML(obj.to_s)
|
129
|
+
end
|
120
130
|
end
|
121
131
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|