flayyer_liquid 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +147 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +21 -0
- data/README.md +215 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/flayyer_liquid.gemspec +31 -0
- data/lib/flayyer_liquid.rb +60 -0
- data/lib/flayyer_liquid/version.rb +3 -0
- metadata +60 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 82818a255a2b36fa7fc664a360ae24b34cf18d91ee8757265f46c433d4366cea
|
|
4
|
+
data.tar.gz: c21f496baa89ee9d7f35601b7fa15c2a32a136844ab56b26df42a1652a122532
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 215c4b850f1d2cfb620a05f270c26eb5fb934b23c6b29efa48b7a79dff898420a99bffdabe15bcfc0a8fda1783e0f79e7eef79d6854ac187c55210d240bfe083
|
|
7
|
+
data.tar.gz: 43bc5a6436c19622acb2fc81b23b9a838006fb4ff868b8fe140b04d6de4009cdcfb46f62911d296a0f4eaf8c922d461544fe851341ca4d1a64673828051bc11d
|
data/.gitignore
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Custom
|
|
2
|
+
/.bundle/
|
|
3
|
+
/.yardoc
|
|
4
|
+
/_yardoc/
|
|
5
|
+
/coverage/
|
|
6
|
+
/doc/
|
|
7
|
+
/pkg/
|
|
8
|
+
/spec/reports/
|
|
9
|
+
/tmp/
|
|
10
|
+
|
|
11
|
+
# rspec failure tracking
|
|
12
|
+
.rspec_status
|
|
13
|
+
|
|
14
|
+
# Created by https://www.toptal.com/developers/gitignore/api/ruby,osx,windows,linux
|
|
15
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=ruby,osx,windows,linux
|
|
16
|
+
|
|
17
|
+
### Linux ###
|
|
18
|
+
*~
|
|
19
|
+
|
|
20
|
+
# temporary files which can be created if a process still has a handle open of a deleted file
|
|
21
|
+
.fuse_hidden*
|
|
22
|
+
|
|
23
|
+
# KDE directory preferences
|
|
24
|
+
.directory
|
|
25
|
+
|
|
26
|
+
# Linux trash folder which might appear on any partition or disk
|
|
27
|
+
.Trash-*
|
|
28
|
+
|
|
29
|
+
# .nfs files are created when an open file is removed but is still being accessed
|
|
30
|
+
.nfs*
|
|
31
|
+
|
|
32
|
+
### OSX ###
|
|
33
|
+
# General
|
|
34
|
+
.DS_Store
|
|
35
|
+
.AppleDouble
|
|
36
|
+
.LSOverride
|
|
37
|
+
|
|
38
|
+
# Icon must end with two \r
|
|
39
|
+
Icon
|
|
40
|
+
|
|
41
|
+
# Thumbnails
|
|
42
|
+
._*
|
|
43
|
+
|
|
44
|
+
# Files that might appear in the root of a volume
|
|
45
|
+
.DocumentRevisions-V100
|
|
46
|
+
.fseventsd
|
|
47
|
+
.Spotlight-V100
|
|
48
|
+
.TemporaryItems
|
|
49
|
+
.Trashes
|
|
50
|
+
.VolumeIcon.icns
|
|
51
|
+
.com.apple.timemachine.donotpresent
|
|
52
|
+
|
|
53
|
+
# Directories potentially created on remote AFP share
|
|
54
|
+
.AppleDB
|
|
55
|
+
.AppleDesktop
|
|
56
|
+
Network Trash Folder
|
|
57
|
+
Temporary Items
|
|
58
|
+
.apdisk
|
|
59
|
+
|
|
60
|
+
### Ruby ###
|
|
61
|
+
*.gem
|
|
62
|
+
*.rbc
|
|
63
|
+
/.config
|
|
64
|
+
/coverage/
|
|
65
|
+
/InstalledFiles
|
|
66
|
+
/pkg/
|
|
67
|
+
/spec/reports/
|
|
68
|
+
/spec/examples.txt
|
|
69
|
+
/test/tmp/
|
|
70
|
+
/test/version_tmp/
|
|
71
|
+
/tmp/
|
|
72
|
+
|
|
73
|
+
# Used by dotenv library to load environment variables.
|
|
74
|
+
# .env
|
|
75
|
+
|
|
76
|
+
# Ignore Byebug command history file.
|
|
77
|
+
.byebug_history
|
|
78
|
+
|
|
79
|
+
## Specific to RubyMotion:
|
|
80
|
+
.dat*
|
|
81
|
+
.repl_history
|
|
82
|
+
build/
|
|
83
|
+
*.bridgesupport
|
|
84
|
+
build-iPhoneOS/
|
|
85
|
+
build-iPhoneSimulator/
|
|
86
|
+
|
|
87
|
+
## Specific to RubyMotion (use of CocoaPods):
|
|
88
|
+
#
|
|
89
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
|
90
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
|
91
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
|
92
|
+
# vendor/Pods/
|
|
93
|
+
|
|
94
|
+
## Documentation cache and generated files:
|
|
95
|
+
/.yardoc/
|
|
96
|
+
/_yardoc/
|
|
97
|
+
/doc/
|
|
98
|
+
/rdoc/
|
|
99
|
+
|
|
100
|
+
## Environment normalization:
|
|
101
|
+
/.bundle/
|
|
102
|
+
/vendor/bundle
|
|
103
|
+
/lib/bundler/man/
|
|
104
|
+
|
|
105
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
106
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
107
|
+
# Gemfile.lock
|
|
108
|
+
# .ruby-version
|
|
109
|
+
# .ruby-gemset
|
|
110
|
+
|
|
111
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
112
|
+
.rvmrc
|
|
113
|
+
|
|
114
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
|
115
|
+
# .rubocop-https?--*
|
|
116
|
+
|
|
117
|
+
### Ruby Patch ###
|
|
118
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
|
119
|
+
# .rubocop-https?--*
|
|
120
|
+
|
|
121
|
+
### Windows ###
|
|
122
|
+
# Windows thumbnail cache files
|
|
123
|
+
Thumbs.db
|
|
124
|
+
Thumbs.db:encryptable
|
|
125
|
+
ehthumbs.db
|
|
126
|
+
ehthumbs_vista.db
|
|
127
|
+
|
|
128
|
+
# Dump file
|
|
129
|
+
*.stackdump
|
|
130
|
+
|
|
131
|
+
# Folder config file
|
|
132
|
+
[Dd]esktop.ini
|
|
133
|
+
|
|
134
|
+
# Recycle Bin used on file shares
|
|
135
|
+
$RECYCLE.BIN/
|
|
136
|
+
|
|
137
|
+
# Windows Installer files
|
|
138
|
+
*.cab
|
|
139
|
+
*.msi
|
|
140
|
+
*.msix
|
|
141
|
+
*.msm
|
|
142
|
+
*.msp
|
|
143
|
+
|
|
144
|
+
# Windows shortcuts
|
|
145
|
+
*.lnk
|
|
146
|
+
|
|
147
|
+
# End of https://www.toptal.com/developers/gitignore/api/ruby,osx,windows,linux
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
flayyer_liquid (1.0.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.4.4)
|
|
10
|
+
flayyer (1.0.0)
|
|
11
|
+
liquid (4.0.3)
|
|
12
|
+
rake (12.3.3)
|
|
13
|
+
rspec (3.9.0)
|
|
14
|
+
rspec-core (~> 3.9.0)
|
|
15
|
+
rspec-expectations (~> 3.9.0)
|
|
16
|
+
rspec-mocks (~> 3.9.0)
|
|
17
|
+
rspec-core (3.9.2)
|
|
18
|
+
rspec-support (~> 3.9.3)
|
|
19
|
+
rspec-expectations (3.9.2)
|
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
21
|
+
rspec-support (~> 3.9.0)
|
|
22
|
+
rspec-mocks (3.9.1)
|
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
24
|
+
rspec-support (~> 3.9.0)
|
|
25
|
+
rspec-support (3.9.3)
|
|
26
|
+
|
|
27
|
+
PLATFORMS
|
|
28
|
+
ruby
|
|
29
|
+
|
|
30
|
+
DEPENDENCIES
|
|
31
|
+
flayyer (~> 1.0.0)
|
|
32
|
+
flayyer_liquid!
|
|
33
|
+
liquid
|
|
34
|
+
rake (~> 12.0)
|
|
35
|
+
rspec (~> 3.0)
|
|
36
|
+
|
|
37
|
+
BUNDLED WITH
|
|
38
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Patricio López Juri
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# flayyer-ruby-liquid (flayyer_liquid)
|
|
2
|
+
|
|
3
|
+
This gem is agnostic to any Ruby framework and is meant to be used alongside [shopify/liquid](https://github.com/Shopify/liquid).
|
|
4
|
+
|
|
5
|
+
To create a FLAYYER template please refer to: [flayyer.com](https://flayyer.com?ref=flayyer-ruby-liquid)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'flayyer'
|
|
13
|
+
gem 'flayyer_liquid'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
And then execute:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
bundle install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or install it yourself as:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
gem install flayyer flayyer_liquid
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
After installing the gem you need to register our custom tag to render Flayyer urls. You can do this on any file you are setting up liquid or any config files that executes when starting up the application.
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
require 'flayyer_liquid'
|
|
34
|
+
|
|
35
|
+
Liquid::Template.register_tag('flayyer', FlayyerLiquid::FlayyerTag)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Just for reference, the programmatic usage is:
|
|
39
|
+
|
|
40
|
+
```ruby
|
|
41
|
+
# Register tag
|
|
42
|
+
Liquid::Template.register_tag('flayyer', FlayyerLiquid::FlayyerTag)
|
|
43
|
+
|
|
44
|
+
# Set defaults
|
|
45
|
+
template = Liquid::Template.parse("{% flayyer tenant: 'tenant', deck: 'my-deck', template: 'post' %}")
|
|
46
|
+
|
|
47
|
+
# Set variables and also you can override defaults by prefixing liquid variables with `flayyer_`
|
|
48
|
+
url = template.render('flayyer_variables' => { title: 'Hello world!' })
|
|
49
|
+
url = template.render({ 'flayyer_variables' => { title: 'Hello world!' }, 'flayyer_template' => 'gallery', 'flayyer_extension' => 'png' })
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
For convenience, adicional variables passed to `{% flayyer ... %}` tag will be treated as Flayyer variables. This is useful if your Flayyer template has a title variable, here is an example:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
template = Liquid::Template.parse(
|
|
56
|
+
"{% flayyer tenant: 't', deck: 'd', template: 'post', title: 'My Post' %}"
|
|
57
|
+
)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
This works with Liquid variables:
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
template = Liquid::Template.parse(
|
|
64
|
+
"{% flayyer tenant: 't', deck: 'd', template: 'post', title: '{{ post.title }}' %}"
|
|
65
|
+
)
|
|
66
|
+
url = template.render('post' => { title: 'My Post' })
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Use quotes around Liquid variables
|
|
70
|
+
|
|
71
|
+
Prevent this common mistake:
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
# This is wrong ❌
|
|
75
|
+
{% flayyer title: {{ post.title }} %}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
# This is correct ✅
|
|
80
|
+
{% flayyer title: '{{ post.title }}' %}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**IMPORTANT: variables must be serializable.**
|
|
84
|
+
|
|
85
|
+
## Liquid templates
|
|
86
|
+
|
|
87
|
+
Here is an example:
|
|
88
|
+
|
|
89
|
+
```html
|
|
90
|
+
<head>
|
|
91
|
+
<meta
|
|
92
|
+
property="og:image"
|
|
93
|
+
content="{% flayyer tenant: 't', deck: 'd', template: 'product', title: '{{ product.title }}', description: '{{ product.description }}' %}"
|
|
94
|
+
>
|
|
95
|
+
</head>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Shopify Integration
|
|
99
|
+
|
|
100
|
+
> Based on https://shopify.github.io/liquid-code-examples/example/open-graph-tags
|
|
101
|
+
|
|
102
|
+
Feel free to change images sizes from the filter [`img_url`](https://shopify.dev/docs/themes/liquid/reference/filters/url-filters) depending of how your Flayyer templates renders each type of preview.
|
|
103
|
+
|
|
104
|
+
```html
|
|
105
|
+
{%- assign og_title = page_title -%}
|
|
106
|
+
{%- assign og_url = canonical_url -%}
|
|
107
|
+
{%- assign og_type = 'website' -%}
|
|
108
|
+
{%- assign og_description = page_description | default: shop.description | default: shop.name -%}
|
|
109
|
+
|
|
110
|
+
{%- if settings.share_image -%}
|
|
111
|
+
{%- capture og_image_tags -%}
|
|
112
|
+
<--! FLAYYER integration starts -->
|
|
113
|
+
{%- assign original_image = settings.share_image | img_url: '1200x630' -%}
|
|
114
|
+
<meta
|
|
115
|
+
property="og:image"
|
|
116
|
+
content="{% flayyer tenant: 'tenant', deck: 'deck', template: 'main', title: '{{ og_title }}', image: '{{ original_image }}' %}"
|
|
117
|
+
>
|
|
118
|
+
<--! FLAYYER integration ends -->
|
|
119
|
+
{%- endcapture -%}
|
|
120
|
+
{%- endif -%}
|
|
121
|
+
|
|
122
|
+
{%- case template.name -%}
|
|
123
|
+
{%- when 'product' -%}
|
|
124
|
+
{%- assign og_title = product.title | strip_html -%}
|
|
125
|
+
{%- assign og_type = 'product' -%}
|
|
126
|
+
|
|
127
|
+
{%- if product.images.size > 0 -%}
|
|
128
|
+
{%- capture og_image_tags -%}
|
|
129
|
+
{%- for image in product.images limit:3 -%}
|
|
130
|
+
<--! FLAYYER integration starts -->
|
|
131
|
+
{%- assign original_image = image.src | product_img_url: '800x800' -%}
|
|
132
|
+
<meta
|
|
133
|
+
property="og:image"
|
|
134
|
+
content="{% flayyer tenant: 'tenant', deck: 'deck', template: 'main', title: '{{ og_title }}', image: '{{ original_image }}' %}"
|
|
135
|
+
>
|
|
136
|
+
<--! FLAYYER integration ends -->
|
|
137
|
+
{%- endfor -%}
|
|
138
|
+
{%- endcapture -%}
|
|
139
|
+
{%- endif -%}
|
|
140
|
+
|
|
141
|
+
{%- when 'article' -%}
|
|
142
|
+
{%- assign og_title = article.title | strip_html -%}
|
|
143
|
+
{%- assign og_type = 'article' -%}
|
|
144
|
+
{%- assign og_description = article.excerpt_or_content | strip_html -%}
|
|
145
|
+
|
|
146
|
+
{%- if article.image -%}
|
|
147
|
+
{%- capture og_image_tags -%}
|
|
148
|
+
<--! FLAYYER integration starts -->
|
|
149
|
+
{%- assign original_image = article.src | product_img_url: '800x800' -%}
|
|
150
|
+
<meta
|
|
151
|
+
property="og:image"
|
|
152
|
+
content="{% flayyer tenant: 'tenant', deck: 'deck', template: 'main', title: '{{ og_title }}', description: '{{ og_description }}', image: '{{ original_image }}' %}"
|
|
153
|
+
>
|
|
154
|
+
<--! FLAYYER integration ends -->
|
|
155
|
+
{%- endcapture -%}
|
|
156
|
+
{%- endif -%}
|
|
157
|
+
|
|
158
|
+
{%- when 'collection' -%}
|
|
159
|
+
{%- assign og_title = collection.title | strip_html -%}
|
|
160
|
+
{%- assign og_type = 'product.group' -%}
|
|
161
|
+
|
|
162
|
+
{%- if collection.image -%}
|
|
163
|
+
{%- capture og_image_tags -%}
|
|
164
|
+
<--! FLAYYER integration starts -->
|
|
165
|
+
{%- assign original_image = collection.src | product_img_url: '800x800' -%}
|
|
166
|
+
<meta
|
|
167
|
+
property="og:image"
|
|
168
|
+
content="{% flayyer tenant: 'tenant', deck: 'deck', template: 'main', title: '{{ og_title }}', image: '{{ original_image }}' %}"
|
|
169
|
+
>
|
|
170
|
+
<--! FLAYYER integration ends -->
|
|
171
|
+
{%- endcapture -%}
|
|
172
|
+
{%- endif -%}
|
|
173
|
+
|
|
174
|
+
{%- when 'password' -%}
|
|
175
|
+
{%- assign og_title = shop.name -%}
|
|
176
|
+
{%- assign og_url = shop.url -%}
|
|
177
|
+
{%- assign og_description = shop.description | default: shop.name -%}
|
|
178
|
+
|
|
179
|
+
{%- endcase -%}
|
|
180
|
+
|
|
181
|
+
<meta property="og:site_name" content="{{ shop.name }}">
|
|
182
|
+
<meta property="og:url" content="{{ og_url }}">
|
|
183
|
+
<meta property="og:title" content="{{ og_title }}">
|
|
184
|
+
<meta property="og:type" content="{{ og_type }}">
|
|
185
|
+
<meta property="og:description" content="{{ og_description }}">
|
|
186
|
+
|
|
187
|
+
{%- if template.name == 'product' -%}
|
|
188
|
+
<meta property="og:price:amount" content="{{ product.price | money_without_currency | strip_html }}">
|
|
189
|
+
<meta property="og:price:currency" content="{{ shop.currency }}">
|
|
190
|
+
{%- endif -%}
|
|
191
|
+
|
|
192
|
+
{{ og_image_tags }}
|
|
193
|
+
|
|
194
|
+
{%- unless settings.social_twitter_link == blank -%}
|
|
195
|
+
<meta name="twitter:site" content="{{ settings.social_twitter_link | split: 'twitter.com/' | last | prepend: '@' }}">
|
|
196
|
+
{%- endunless -%}
|
|
197
|
+
|
|
198
|
+
<meta name="twitter:card" content="summary_large_image">
|
|
199
|
+
<meta name="twitter:title" content="{{ og_title }}">
|
|
200
|
+
<meta name="twitter:description" content="{{ og_description }}">
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Development
|
|
204
|
+
|
|
205
|
+
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.
|
|
206
|
+
|
|
207
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
208
|
+
|
|
209
|
+
## Contributing
|
|
210
|
+
|
|
211
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/flayyer/flayyer-ruby-liquid.
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "flayyer"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require_relative 'lib/flayyer_liquid/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = 'flayyer_liquid'
|
|
5
|
+
spec.version = FlayyerLiquid::VERSION
|
|
6
|
+
spec.authors = ['Patricio López Juri']
|
|
7
|
+
spec.email = ['patricio@flayyer.com']
|
|
8
|
+
|
|
9
|
+
spec.summary = 'FLAYYER.com helper classes and methods'
|
|
10
|
+
# spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
|
|
11
|
+
spec.description = 'FLAYYER.com helper classes and methods'
|
|
12
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
|
13
|
+
spec.homepage = 'https://github.com/flayyer/flayyer-ruby-liquid'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
|
16
|
+
|
|
17
|
+
# spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com''
|
|
18
|
+
|
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/flayyer/flayyer-ruby-liquid'
|
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/flayyer/flayyer-ruby-liquid'
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = 'exe'
|
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ['lib']
|
|
31
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'flayyer_liquid/version'
|
|
2
|
+
require 'flayyer'
|
|
3
|
+
require 'liquid'
|
|
4
|
+
|
|
5
|
+
module FlayyerLiquid
|
|
6
|
+
class Error < StandardError; end
|
|
7
|
+
|
|
8
|
+
class FlayyerTag < Liquid::Tag
|
|
9
|
+
attr_accessor :params
|
|
10
|
+
attr_accessor :version, :tenant, :deck, :template, :extension, :variables
|
|
11
|
+
|
|
12
|
+
def initialize(tag_name, params, tokens)
|
|
13
|
+
super
|
|
14
|
+
@params = params
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def render(context)
|
|
18
|
+
@variables = {}
|
|
19
|
+
@version = '_' # latest
|
|
20
|
+
@extension = 'jpeg'
|
|
21
|
+
|
|
22
|
+
# Pre-render values enclosed in {{ }}
|
|
23
|
+
params = Liquid::Template.parse(@params).render(context)
|
|
24
|
+
|
|
25
|
+
# TODO: Since 2015 there is no official way of passing multiple args
|
|
26
|
+
params.scan(Liquid::TagAttributes) do |key, value|
|
|
27
|
+
value = value.gsub(/^'|"/, '').gsub(/'|"$/, '')
|
|
28
|
+
case key
|
|
29
|
+
when 'tenant'
|
|
30
|
+
@tenant = value
|
|
31
|
+
when 'deck'
|
|
32
|
+
@deck = value
|
|
33
|
+
when 'template'
|
|
34
|
+
@template = value
|
|
35
|
+
when 'version'
|
|
36
|
+
@version = value
|
|
37
|
+
when 'extension'
|
|
38
|
+
@extension = value
|
|
39
|
+
else
|
|
40
|
+
@variables[key] = value
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
flayyer = Flayyer::FlayyerURL.create do |f|
|
|
45
|
+
f.tenant = context['flayyer_tenant'].nil? || context['flayyer_tenant'].empty? ? @tenant : context['flayyer_tenant']
|
|
46
|
+
f.deck = context['flayyer_deck'].nil? || context['flayyer_deck'].empty? ? @deck : context['flayyer_deck']
|
|
47
|
+
f.template = context['flayyer_template'].nil? || context['flayyer_template'].empty? ? @template : context['flayyer_template']
|
|
48
|
+
f.variables = context['flayyer_variables'].nil? || context['flayyer_variables'].empty? ? @variables : context['flayyer_variables']
|
|
49
|
+
f.version = context['flayyer_version'].nil? || context['flayyer_version'].empty? ? @version : context['flayyer_version']
|
|
50
|
+
f.extension = context['flayyer_extension'].nil? || context['flayyer_extension'].empty? ? @extension : context['flayyer_extension']
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
begin
|
|
54
|
+
return flayyer.href
|
|
55
|
+
rescue Flayyer::Error # missing tenant, deck or template
|
|
56
|
+
return ''
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: flayyer_liquid
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Patricio López Juri
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-08-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: FLAYYER.com helper classes and methods
|
|
14
|
+
email:
|
|
15
|
+
- patricio@flayyer.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- ".gitignore"
|
|
21
|
+
- ".rspec"
|
|
22
|
+
- ".travis.yml"
|
|
23
|
+
- Gemfile
|
|
24
|
+
- Gemfile.lock
|
|
25
|
+
- LICENSE.txt
|
|
26
|
+
- README.md
|
|
27
|
+
- Rakefile
|
|
28
|
+
- bin/console
|
|
29
|
+
- bin/setup
|
|
30
|
+
- flayyer_liquid.gemspec
|
|
31
|
+
- lib/flayyer_liquid.rb
|
|
32
|
+
- lib/flayyer_liquid/version.rb
|
|
33
|
+
homepage: https://github.com/flayyer/flayyer-ruby-liquid
|
|
34
|
+
licenses:
|
|
35
|
+
- MIT
|
|
36
|
+
metadata:
|
|
37
|
+
homepage_uri: https://github.com/flayyer/flayyer-ruby-liquid
|
|
38
|
+
source_code_uri: https://github.com/flayyer/flayyer-ruby-liquid
|
|
39
|
+
changelog_uri: https://github.com/flayyer/flayyer-ruby-liquid
|
|
40
|
+
post_install_message:
|
|
41
|
+
rdoc_options: []
|
|
42
|
+
require_paths:
|
|
43
|
+
- lib
|
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: 2.3.0
|
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
requirements: []
|
|
55
|
+
rubyforge_project:
|
|
56
|
+
rubygems_version: 2.7.6.2
|
|
57
|
+
signing_key:
|
|
58
|
+
specification_version: 4
|
|
59
|
+
summary: FLAYYER.com helper classes and methods
|
|
60
|
+
test_files: []
|