webflow_sync 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c1e92b51a65d85955a3e252f59660dcf59932a7bcca492c7ce439e660efb762
|
4
|
+
data.tar.gz: 3befa85279c19ad561d4b5dd15f1fc2446d89238027969739f98a53966ea6897
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35bc4a6a9f7b50ff5b1c5062f1554a37f5b2e12e439d8cead8b07188ab70de0d184499ade1caa0b102668d06332515de580507fce0cd9109e1ff17b0ac871710
|
7
|
+
data.tar.gz: fbfa04746a2faa8f34b30879589c2857ecf1ab9bd04b907119f5ad6cce702ec2fc5f7e9d441c3c7145b14cf25607aabd717de45abcb359252ab650dc2f3d0e4b
|
data/README.md
CHANGED
@@ -82,17 +82,27 @@ Please note that this _does not_ create a WebFlow collection as that's not possi
|
|
82
82
|
|
83
83
|
As mentioned above, you need to create the WebFlow collection yourself.
|
84
84
|
|
85
|
-
Make sure that the collection `slug` matches the Rails model collection name (the output of `model_class.model_name.
|
85
|
+
Make sure that the collection `slug` matches the Rails model collection name (the output of `model_class.model_name.to_s.underscore.dasherize.pluralize`).
|
86
86
|
|
87
87
|
For example, for `Article` model:
|
88
88
|
|
89
89
|
```ruby
|
90
|
-
> Article.model_name.
|
90
|
+
> Article.model_name.to_s.underscore.dasherize.pluralize
|
91
91
|
# => "articles"
|
92
92
|
```
|
93
93
|
|
94
94
|
Your WebFlow collection `slug` should be `"articles"`.
|
95
95
|
|
96
|
+
For Rails models named with multiple words, make a collection that have a space between words in the name. WebFlow will set the `slug` by replacing space for "-".
|
97
|
+
|
98
|
+
For example, for `FeaturedArticle` model:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
> FeaturedArticle.model_name.to_s.underscore.dasherize.pluralize
|
102
|
+
# => "featured-articles"
|
103
|
+
```
|
104
|
+
Your WebFlow collection `slug` in this case should be `"featured-articles"`.
|
105
|
+
|
96
106
|
### Set `webflow_site_id`
|
97
107
|
|
98
108
|
There are couple of ways how you can set the `webflow_site_id` to be used.
|
@@ -166,6 +176,36 @@ class Article < ApplicationRecord
|
|
166
176
|
end
|
167
177
|
```
|
168
178
|
|
179
|
+
### Sync a Rails model with the custom collection
|
180
|
+
|
181
|
+
If collection `slug` does not match the Rails model collection name, you can still sync with WebFlow collection, but need to specify collection slug for each `CreateItemJob` and `UpdateItemJob` call. If not specified, model name is used as a default slug name.
|
182
|
+
You would also need to replace included `WebflowSync::ItemSync` with custom callbacks that will call appropriate WebflowSync jobs.
|
183
|
+
|
184
|
+
For example:
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
WebflowSync::CreateItemJob.perform_later(model_name, id, collection_slug)
|
188
|
+
WebflowSync::UpdateItemJob.perform_later(model_name, id, collection_slug)
|
189
|
+
WebflowSync::DestroyItemJob.perform_later(collection_slug:, webflow_site_id:, webflow_item_id:)
|
190
|
+
```
|
191
|
+
|
192
|
+
Where:
|
193
|
+
|
194
|
+
1. `model_name` - Rails model that has `webflow_site_id` and `webflow_item_id` defined
|
195
|
+
2. `collection_slug` - slug of the WebFlow collection (defaults to: `model_name.underscore.dasherize.pluralize `)
|
196
|
+
|
197
|
+
|
198
|
+
For example:
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
WebflowSync::CreateItemJob.perform_now('articles', 1, 'stories')
|
202
|
+
```
|
203
|
+
Or, if you want to use the default 'articles' collection_slug:
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
WebflowSync::CreateItemJob.perform_now('articles', 1)
|
207
|
+
```
|
208
|
+
|
169
209
|
### Run the initial sync
|
170
210
|
|
171
211
|
After setting up which models you want to sync to WebFlow, you can run the initial sync for each of the models:
|
@@ -2,8 +2,16 @@
|
|
2
2
|
|
3
3
|
module WebflowSync
|
4
4
|
class CreateItemJob < ApplicationJob
|
5
|
-
|
6
|
-
|
5
|
+
# WebFlow collection slug should be in plural form.
|
6
|
+
# For collections that have spaces in their name, WebFlow sets slug by replacing space for "-".
|
7
|
+
# 'JobListing'.underscore.dasherize.pluralize => "job-listings"
|
8
|
+
# 'job_listing'.underscore.dasherize.pluralize => "job-listings"
|
9
|
+
# We can sync Rails model that has different class name than its WebFlow collection
|
10
|
+
# model_name => Rails model that has webflow_site_id and webflow_item_id columns
|
11
|
+
# collection_slug => slug of the WebFlow collection
|
12
|
+
# model_name = 'articles'; id = article.id, collection_slug = 'stories'
|
13
|
+
def perform(model_name, id, collection_slug = model_name.underscore.dasherize.pluralize)
|
14
|
+
model_class = model_name.underscore.classify.constantize
|
7
15
|
record = model_class.find_by(id: id)
|
8
16
|
return if record.blank?
|
9
17
|
return if record.webflow_site_id.blank?
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module WebflowSync
|
4
4
|
class InitialSyncJob < ApplicationJob
|
5
5
|
def perform(collection_slug)
|
6
|
-
model_class = collection_slug.classify.constantize
|
6
|
+
model_class = collection_slug.underscore.classify.constantize
|
7
7
|
model_class.where(webflow_item_id: nil).find_each do |record|
|
8
8
|
next if record.webflow_site_id.blank?
|
9
9
|
|
@@ -2,12 +2,16 @@
|
|
2
2
|
|
3
3
|
module WebflowSync
|
4
4
|
class UpdateItemJob < ApplicationJob
|
5
|
-
|
6
|
-
|
5
|
+
# WebFlow collection slug should be in plural form.
|
6
|
+
# For collections that have spaces in their name, WebFlow sets slug by replacing space for "-".
|
7
|
+
# 'JobListing'.underscore.dasherize.pluralize => 'job-listings'
|
8
|
+
# 'job_listing'.underscore.dasherize.pluralize => 'job-listings'
|
9
|
+
def perform(model_name, id, collection_slug = model_name.underscore.dasherize.pluralize)
|
10
|
+
model_class = model_name.underscore.classify.constantize
|
7
11
|
record = model_class.find_by(id: id)
|
8
12
|
return if record.blank?
|
9
13
|
return if record.webflow_site_id.blank?
|
10
|
-
return WebflowSync::CreateItemJob.perform_now(
|
14
|
+
return WebflowSync::CreateItemJob.perform_now(model_name, id, collection_slug) if record.webflow_item_id.blank?
|
11
15
|
|
12
16
|
WebflowSync::Api.new(record.webflow_site_id).update_item(record, collection_slug)
|
13
17
|
end
|
data/lib/webflow_sync/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webflow_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viktor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|