Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/unabris/liquid-tag-attribute_parser
Liquid::Tag::AttributeParser allows you to send familiar html-like attributes along with your Liquid tags to receive back a more manageable Ruby hash with all the given information.
https://github.com/unabris/liquid-tag-attribute_parser
jekyll liquid
Last synced: 3 months ago
JSON representation
Liquid::Tag::AttributeParser allows you to send familiar html-like attributes along with your Liquid tags to receive back a more manageable Ruby hash with all the given information.
- Host: GitHub
- URL: https://github.com/unabris/liquid-tag-attribute_parser
- Owner: unabris
- License: mit
- Created: 2021-08-22T13:25:06.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-16T19:19:53.000Z (8 months ago)
- Last Synced: 2024-10-09T10:35:35.233Z (3 months ago)
- Topics: jekyll, liquid
- Language: Ruby
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Liquid::Tag::AttributeParser
![Gem](https://img.shields.io/gem/v/liquid-tag-attribute_parser)
[![Maintainability](https://api.codeclimate.com/v1/badges/5aad2d37fdb6fc3acfd9/maintainability)](https://codeclimate.com/github/unabris/liquid-tag-attribute_parser/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/5aad2d37fdb6fc3acfd9/test_coverage)](https://codeclimate.com/github/unabris/liquid-tag-attribute_parser/test_coverage)
![GitHub](https://img.shields.io/github/license/unabris/liquid-tag-attribute_parser)`Liquid::Tag::AttributeParser` allows you to send familiar `html`-like attributes along with your Liquid tags to receive back a more manageable Ruby hash with all the given information.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'liquid-tag-attribute_parser'
```And then execute:
```shell
$ bundle install
```Or install it yourself as:
```shell
$ gem install liquid-tag-attribute_parser
```
## UsageThree easy steps:
1. Take the raw argument data you get from the Liquid Tag
1. Use `Liquid::Tag::AttributeParser` to parse the raw data
1. Get back the data on a Hash format#### Working example for [Jekyll tags](https://jekyllrb.com/docs/plugins/tags/):
```ruby
require "liquid/tag/attribute_parser"module Jekyll
class GreetingTag < Liquid::Tag
def initialize(_tag_name, text, _tokens)
super
@attributes = Liquid::Tag::AttributeParser.new(text).attributes
enddef render(_context)
"Hello! My name is #{@attributes[:name]} and I'm #{@attributes[:age]}"
end
end
endLiquid::Template.register_tag('greeting', Jekyll::GreetingTag)
``````html
{% greeting name="Jekyll" age=13 %}
```## Supported data types
### `String`
```ruby
Liquid::Tag::AttributeParser.new('string="This is a string"').attributes# => {:string=>"This is a string"}
```### `Boolean`
```ruby
Liquid::Tag::AttributeParser.new('boolean=true').attributes# => {:boolean=>true}
``````ruby
Liquid::Tag::AttributeParser.new('boolean=false').attributes# => {:boolean=>false}
```### `Integer`
```ruby
Liquid::Tag::AttributeParser.new('integer=123').attributes# => {:integer=>123}
``````ruby
Liquid::Tag::AttributeParser.new('integer=+123').attributes# => {:integer=>123}
``````ruby
Liquid::Tag::AttributeParser.new('integer=-123').attributes# => {:integer=>-123}
```### `Float`
```ruby
Liquid::Tag::AttributeParser.new('float=1.23').attributes# => {:float=>1.23}
``````ruby
Liquid::Tag::AttributeParser.new('float=+1.23').attributes# => {:float=>1.23}
``````ruby
Liquid::Tag::AttributeParser.new('float=-1.23').attributes# => {:float=>-1.23}
``````ruby
Liquid::Tag::AttributeParser.new('float=123.0').attributes# => {:float=>123.0}
``````ruby
Liquid::Tag::AttributeParser.new('float=+123.0').attributes# => {:float=>123.0}
``````ruby
Liquid::Tag::AttributeParser.new('float=-123.0').attributes# => {:float=>-123.0}
``````ruby
Liquid::Tag::AttributeParser.new('float=.123').attributes# => {:float=>0.123}
``````ruby
Liquid::Tag::AttributeParser.new('float=+.123').attributes# => {:float=>0.123}
``````ruby
Liquid::Tag::AttributeParser.new('float=-.123').attributes# => {:float=>-0.123}
```### Combination of different data types
```ruby
Liquid::Tag::AttributeParser.new('string="This is a string" boolean=true integer=-123 float=.123').attributes# => {:string=>"This is a string", :boolean=>true, :integer=>-123, :float=>0.123}
```## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/unabris/liquid-tag-attribute_parser.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).