Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blakewilliams/component_embedded_ruby
Strict Ruby templates with component support
https://github.com/blakewilliams/component_embedded_ruby
Last synced: 16 days ago
JSON representation
Strict Ruby templates with component support
- Host: GitHub
- URL: https://github.com/blakewilliams/component_embedded_ruby
- Owner: BlakeWilliams
- License: mit
- Created: 2019-10-30T22:27:33.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-19T20:31:49.000Z (almost 2 years ago)
- Last Synced: 2024-11-24T08:32:50.295Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 97.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Component Embedded Ruby
Strict HTML templating with support for components.
### Features:
* Strict HTML parsing. eg: matching end tags are enforced
* HTML attributes are either static, or dynamic. No more `class="hello <%=
extra_classes %>`, instead this logic should be pushed up to components.
* Component rendering has a single dependency, a `render` method being present
in the rendering context.
* automatic Rails support for `crb` extension### Usage
Define a template:
```ruby
hello world
```Define a component
```ruby
class Capitalization
def initialize(upcase: false)
@upcase = upcase
enddef render_in(_view_context)
children = yieldif @upcase
children.upcase
else
children
end
end
end
```Render it
```ruby
ComponentEmbeddedRuby.render(template_string)
```See results
```html
HELLO WORLD
```If trying to render outside of a Rails environment, ensure that the binding
passed to the renderer has a top-level `render` method that can accept component
instances and convert them to strings.e.g. the most basic example could look like this:
```ruby
def render(renderable, &block)
# This assumes components being rendered utilize `to_s` to render their
# templates
renderable.to_s(&block)
end
```For more examples, check out the `ComponentEmbeddedRuby::Renderable` tests.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/BlakeWilliams/component_embedded_ruby.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).