https://github.com/opencomponents/ruby-oc
OpenComponents for Ruby
https://github.com/opencomponents/ruby-oc
Last synced: 11 months ago
JSON representation
OpenComponents for Ruby
- Host: GitHub
- URL: https://github.com/opencomponents/ruby-oc
- Owner: opencomponents
- License: mit
- Created: 2015-06-25T00:56:02.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-07T03:37:19.000Z (almost 10 years ago)
- Last Synced: 2024-04-20T13:56:33.180Z (almost 2 years ago)
- Language: Ruby
- Homepage:
- Size: 40 KB
- Stars: 5
- Watchers: 29
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# opencomponents
[][1]
[][2]
[][3]
[][4]
[][5]
[1]:https://travis-ci.org/opentable/ruby-oc
[2]:https://coveralls.io/r/opentable/ruby-oc
[3]:https://codeclimate.com/github/opentable/ruby-oc
[4]:http://badge.fury.io/rb/opencomponents
[5]:https://gemnasium.com/opentable/ruby-oc
[OpenComponents][6] for Ruby
[6]:https://github.com/opentable/oc
## Important
This gem is still under heavy development and the API is likely to change at any
time.
## Getting Started
Add the gem to your Gemfile and run `bundle install`:
```ruby
gem 'opencomponents', '~> 0.4.0'
```
By default, the gem will attempt to use a component registry located at
`http://localhost:3030`.
If you want to use a different registry, you can configure OpenComponents to use
it with:
```ruby
OpenComponents.configure { |config| config.registry = 'http://some.other.host' }
```
## Getting Rendered Components
To request an OpenComponent with its rendered HTML, you can create and load a new
`RenderedComponent` object.
```ruby
component = OpenComponents::RenderedComponent.new('my-awesome-component')
component.load
```
Optionally, you can also specify parameters, the component version, and
additional HTTP headers to request:
```ruby
component = OpenComponents::RenderedComponent.new(
'my-awesome-component',
params: {name: 'Kate'},
version: '1.0.2',
headers: {accept_language: 'emoji'}
)
```
## Getting Unrendered Components
If you'd like to perform the component rendering yourself, you can request an
unrendered component from a registry using a `UnrenderedComponent` object.
```ruby
component = OpenComponents::UnrenderedComponent.new('my-awesome-component')
component.load
```
You can use the same optional `params`, `version`, and `headers` arguments as
`RenderedComponent`s.
**Note**: `UnrenderedComponent`s will only fetch component data for you - they
do not provide an interface for rendering them. At the moment, it's up to you to
determine the best way to render the template.
## Integrations
Individual integrations for rendering components in Rails and Sinatra are
available.
* [opencomponents-rails][7]
* [sinatra-opencomponents][8]
[7]:https://github.com/opentable/opencomponents-rails
[8]:https://github.com/opentable/sinatra-opencomponents
## Contributing
Would be rad. Open a PR or Issue if you have an idea for improvements.
## License
Copyright 2015 OpenTable. See LICENSE for details.