opencomponents-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d47325974d4ae94b62bf8fcb3ae04451fc25b51
4
+ data.tar.gz: 0de0e3246eb1f39ec2e895ddbf971c7aeb94fdb9
5
+ SHA512:
6
+ metadata.gz: 1f7f02a3300533e112efdc920cede57711ae24395e707f9403846dccd4649657d68ca6ff584bdc988e6f99b947e3ecbfb7115a1e4de8a25cf3bc76f70d006ab9
7
+ data.tar.gz: ca4d058d2b3cb2e838d2297546c3386ce4b5221049febcaa019d22f65c37fea57fa062ec61cf3bf33c5e06768f1674a2256229fb1d468eb6dae6b7d50ea72aa3
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 OpenTable
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,74 @@
1
+ # OpenComponents::Rails
2
+ [![Build Status](https://travis-ci.org/opentable/opencomponents-rails.svg?branch=master)][1]
3
+
4
+ [1]:https://travis-ci.org/opentable/opencomponents-rails
5
+
6
+ OpenComponents for Rails. This gem provides view helper methods for component
7
+ rendering on both server- and client-side.
8
+
9
+ ## Getting Started
10
+ Add the gem to your Gemfile and run `bundle install`:
11
+
12
+ ```ruby
13
+ gem 'opencomponents-rails'
14
+ ```
15
+
16
+ ### Configuration
17
+ All configuration options are set through Rails environment configuration files.
18
+
19
+ ```ruby
20
+ # production.rb
21
+
22
+ # Sets the registry URL to fetch components from. Defaults to http://localhost:3030.
23
+ config.opencomponents.registry = 'http://my.awesome.registry'
24
+
25
+ # Determines whether rendering should be handed off to the browser if server-side
26
+ # rendering fails. Defaults to true.
27
+ config.opencomponents.enable_client_failover = true
28
+
29
+ # Sets the timeout length (in seconds) for registry requests. Defaults to 5.
30
+ config.opencomponents.request_timeout = 10
31
+ ```
32
+
33
+ ## Rendering
34
+ `OpenComponents::Rails` supports both server- and client-side rendering of components.
35
+ By default, the gem will fall back to client-side rendering if a server-side registry
36
+ request times out. If client-side failover if disabled, an error will be raised instead.
37
+ This is configurable using the `enable_client_failover` option.
38
+
39
+ ### Client-Side Rendering
40
+ The OpenComponents client-side javascript library is bundled with this gem for inclusion
41
+ in the asset compilation process. To enable client-side rendering through the asset
42
+ pipeline, add the library to your javascript manifest:
43
+
44
+ ```javascript
45
+ //= require opencomponents
46
+ ```
47
+
48
+ Once that's done, you can use the `oc_component_tag` method in your views. You can either
49
+ pass the method a fully formed `href` attribute or use the same options as `OpenComponents`
50
+ [Renderer][2].
51
+ ```erb
52
+ <%= oc_component_tag('my-sweet-component', href: 'http://localhost:3030/my-sweet-component/1.0.1?name=Zan') %>
53
+
54
+ <%= oc_component_tag('my-sweet-component', params: {name: 'Zan'}, version: '1.0.1') %>
55
+ ```
56
+
57
+ Components using this tag will be automatically rendered on DOM load.
58
+
59
+ ### Server-Side Rendering
60
+ In your view, simply call `render_component`:
61
+
62
+ ```erb
63
+ <%= render_component('my-sweet-component', params: {name: 'Zan'}, version: '1.0.1') %>
64
+ ```
65
+
66
+ The method accepts the same options as the `OpenComponents` [Renderer][2].
67
+
68
+ [2]:http://www.rubydoc.info/gems/opencomponents/OpenComponents/Renderer
69
+
70
+ ## Contributing
71
+ Would be pretty cool of you. Open an Issue or PR if you find bugs or have ideas for improvements.
72
+
73
+ ## License
74
+ Copyright 2015 OpenTable. See LICENSE for details.
@@ -0,0 +1 @@
1
+ require 'opencomponents/rails'
@@ -0,0 +1,6 @@
1
+ require 'opencomponents'
2
+
3
+ require 'opencomponents/rails/engine'
4
+ require 'opencomponents/rails/railtie'
5
+ require 'opencomponents/rails/renderer'
6
+ require 'opencomponents/rails/version'
@@ -0,0 +1,4 @@
1
+ module OpenComponents::Rails
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,20 @@
1
+ module OpenComponents::Rails
2
+ class Railtie < ::Rails::Railtie
3
+ config.opencomponents = ActiveSupport::OrderedOptions.new
4
+
5
+ config.opencomponents.registry = OpenComponents::DEFAULT_REGISTRY
6
+ config.opencomponents.enable_client_failover = true
7
+ config.opencomponents.request_timeout = OpenComponents::DEFAULT_TIMEOUT
8
+
9
+ initializer 'opencomponents.configure' do |app|
10
+ OpenComponents.configure do |config|
11
+ config.registry = app.config.opencomponents.registry
12
+ config.timeout = app.config.opencomponents.request_timeout
13
+ end
14
+ end
15
+
16
+ initializer 'opencomponents.view_helpers' do
17
+ ActionView::Base.send :include, OpenComponents::Rails::Renderer
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,66 @@
1
+ module OpenComponents::Rails
2
+ module Renderer
3
+ include ::OpenComponents::Renderer
4
+
5
+ include ::ActionView::Helpers::TagHelper
6
+
7
+ # Returns a rendered component.
8
+ #
9
+ # render_component('my-component')
10
+ # # => <oc-component href="http://localhost:3030/my-component">...</oc-component>
11
+ #
12
+ # Also accepts options for "params", "version", and "headers".
13
+ #
14
+ # render_component('my-component',
15
+ # params: {name: 'Zan'},
16
+ # version: '1.0.2',
17
+ # headers: {accept_language: 'emoji'}
18
+ # )
19
+ # # => <oc-component href="http://localhost:3030/my-component/1.0.2?name=Zan">...</oc-component>
20
+ #
21
+ # Raises an error if the registry request times out and client failover is
22
+ # disabled, otherwise will return an unrendered <oc-component> tag for
23
+ # client-side rendered.
24
+ def render_component(component, opts = {})
25
+ super(component, opts).html_safe
26
+ rescue OpenComponents::RegistryTimeout
27
+ config = ::Rails.application.config.opencomponents
28
+
29
+ raise unless config.enable_client_failover
30
+
31
+ oc_component_tag(component, opts)
32
+ end
33
+
34
+ # Returns an unrendered oc-component tag for client-side rendering.
35
+ #
36
+ # oc_component_tag('my-component')
37
+ # # => <oc-component href="localhost:3030/my-component" />
38
+ #
39
+ # Also accepts options for "href", "params", and "version". "params" and
40
+ # "version" are ignored if "href" is passed to the method. If no href is
41
+ # passed, the method attempts to build a valid URL using the configured
42
+ # OC registry, component name, and params and version if they're available.
43
+ #
44
+ # oc_component_tag('my-component', params: {name: 'Zan'}, version: '1.0.2')
45
+ # # => <oc-component href="http://localhost:3030/my-component/1.0.2?name=Zan">
46
+ #
47
+ # oc_component_tag('my-component', href: 'http://some.registry/my-component')
48
+ # # => <oc-component href="http://some.registry/my-component" />
49
+ def oc_component_tag(component, opts = {})
50
+ opts = opts.with_indifferent_access
51
+ options = opts.reject { |k, _| %w(params version).include? k }
52
+
53
+ unless options[:href]
54
+ registry = ::Rails.application.config.opencomponents.registry
55
+
56
+ options[:href] = File.join(
57
+ registry, component, opts[:version].to_s
58
+ )
59
+
60
+ options[:href] << "?#{opts[:params].to_param}" if opts[:params]
61
+ end
62
+
63
+ tag('oc-component', options)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ module OpenComponents
2
+ module Rails
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ $:.unshift File.expand_path('../lib', __FILE__)
4
+ require 'opencomponents/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.required_ruby_version = '>= 1.9.3'
8
+
9
+ spec.add_dependency 'opencomponents', '~> 0.4.0'
10
+ spec.add_dependency 'railties', '~> 4.1', '< 5.0.0.alpha'
11
+ spec.add_development_dependency 'bundler', '~> 1.10'
12
+
13
+ spec.authors = ['Todd Bealmear']
14
+ spec.description = %q{Renders OpenComponents in your Rails views.}
15
+ spec.email = ['tbealmear@opentable.com']
16
+ spec.files = %w(LICENSE README.md opencomponents-rails.gemspec)
17
+ spec.files += Dir.glob('lib/**/*.rb')
18
+ spec.homepage = 'https://github.com/opentable/opencomponents-rails'
19
+ spec.licenses = ['MIT']
20
+ spec.name = 'opencomponents-rails'
21
+ spec.require_paths = ['lib']
22
+ spec.summary = spec.description
23
+ spec.version = OpenComponents::Rails::VERSION
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opencomponents-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Todd Bealmear
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opencomponents
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.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.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 5.0.0.alpha
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '4.1'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 5.0.0.alpha
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.10'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.10'
61
+ description: Renders OpenComponents in your Rails views.
62
+ email:
63
+ - tbealmear@opentable.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - LICENSE
69
+ - README.md
70
+ - lib/opencomponents-rails.rb
71
+ - lib/opencomponents/rails.rb
72
+ - lib/opencomponents/rails/engine.rb
73
+ - lib/opencomponents/rails/railtie.rb
74
+ - lib/opencomponents/rails/renderer.rb
75
+ - lib/opencomponents/rails/version.rb
76
+ - opencomponents-rails.gemspec
77
+ homepage: https://github.com/opentable/opencomponents-rails
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.9.3
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.2.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Renders OpenComponents in your Rails views.
101
+ test_files: []