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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fb150ff5c8b988370259759086c1775d851c5d7b302c223bbd1a1ecf03eaf62
4
- data.tar.gz: 2d298170408b3ff3893353ba62becbfa88212168cd7f3e212aad4011d2c39e2c
3
+ metadata.gz: c5f073b2ec6adad102c5fb898e7071c7531663960f6188c678a1b46c7f564e2f
4
+ data.tar.gz: f0bbc1b2c7cee8fca01ec2f7e0d75b0ca260428e24a50ec6f28a9a70e714b6f7
5
5
  SHA512:
6
- metadata.gz: debdc05c3a309c2ed25334124f3bcfc726c4d92e15fe517d7946f48944ecd78239fb32bb4305f64ee7632bbc7235d6b065f08aefb88bd2b050a01bd9998cc03f
7
- data.tar.gz: f365e4454d2189123524f86cf3f845f06f974beb6d0f4993aaf921523464469b2a1041d10d0db6889fcd493c0a3740a1d9755361d996d886eb79c39f9b85e05b
6
+ metadata.gz: bdfd59e87eccbc6cc0be4a92579813d76195d14e0cfb3620f6ec3a3204730cb8ba35f528d59e260db268bb2a697acb1bb6ccf3c8615fbb52979aa67e15e91858
7
+ data.tar.gz: 76ab042215b76839bab82c36ac19682da07050ed0da54d714ffc6e609160ef360962e445b4ef9f71ade86e35ff2dc65668ace167880c92203c4da565f4d09036
data/.reek.yml CHANGED
@@ -6,6 +6,10 @@ detectors:
6
6
  NestedIterators:
7
7
  ignore_iterators:
8
8
  - each_object
9
+ UtilityFunction:
10
+ enabled: false
11
+ UncommunicativeMethodName:
12
+ enabled: false
9
13
  exclude_paths:
10
14
  - bin
11
15
  - client
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  ---
2
- sudo: false
3
2
  language: ruby
4
3
  cache: bundler
5
4
  rvm:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-component (0.4.1)
4
+ rack-component (0.4.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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)
@@ -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>') #=> &lt;h1&gt;hi&lt;/h1&gt;
127
+ def h(obj)
128
+ CGI.escapeHTML(obj.to_s)
129
+ end
120
130
  end
121
131
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Component
3
- VERSION = '0.4.1'.freeze
3
+ VERSION = '0.4.2'.freeze
4
4
  end
5
5
  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.1
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-02 00:00:00.000000000 Z
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips