Skip to content

Commit 41b28d7

Browse files
authored
Merge pull request #70 from cortex-cms/topic/CE-728-Refactors
CE-728: Refactors
2 parents 40cdd59 + cb79849 commit 41b28d7

13 files changed

+1740
-873
lines changed

.babelrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"modules": false,
5+
"targets": {
6+
"browsers": "> 1%",
7+
"uglify": true
8+
},
9+
"useBuiltIns": true
10+
}]
11+
],
12+
13+
"plugins": [
14+
"syntax-dynamic-import",
15+
"transform-object-rest-spread",
16+
["transform-class-properties", { "spec": true }]
17+
]
18+
}

.postcssrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins:
2+
postcss-import: {}
3+
postcss-cssnext: {}

Gemfile.lock

Lines changed: 82 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,80 @@ PATH
22
remote: .
33
specs:
44
cortex-plugins-core (3.0.0)
5-
aws-sdk-s3 (~> 1.5)
5+
aws-sdk-s3 (~> 1.17)
66
cells (~> 4.1)
77
cells-haml (~> 0.0)
88
cells-rails (~> 0.0)
99
fastimage (~> 2.1)
10-
image_optim (~> 0.25)
10+
image_optim (~> 0.26)
1111
image_optim_pack (~> 0.5)
12-
image_processing (~> 0.4)
12+
image_processing (~> 1.6)
1313
jsonb_accessor (~> 1.0)
1414
mimemagic (~> 0.3)
1515
mini_magick (~> 4.8)
1616
rails (>= 5)
17-
shrine (~> 2.7)
17+
shrine (~> 2.11)
1818

1919
GEM
2020
remote: https://rubygems.org/
2121
specs:
22-
actioncable (5.1.4)
23-
actionpack (= 5.1.4)
22+
actioncable (5.2.0)
23+
actionpack (= 5.2.0)
2424
nio4r (~> 2.0)
25-
websocket-driver (~> 0.6.1)
26-
actionmailer (5.1.4)
27-
actionpack (= 5.1.4)
28-
actionview (= 5.1.4)
29-
activejob (= 5.1.4)
25+
websocket-driver (>= 0.6.1)
26+
actionmailer (5.2.0)
27+
actionpack (= 5.2.0)
28+
actionview (= 5.2.0)
29+
activejob (= 5.2.0)
3030
mail (~> 2.5, >= 2.5.4)
3131
rails-dom-testing (~> 2.0)
32-
actionpack (5.1.4)
33-
actionview (= 5.1.4)
34-
activesupport (= 5.1.4)
32+
actionpack (5.2.0)
33+
actionview (= 5.2.0)
34+
activesupport (= 5.2.0)
3535
rack (~> 2.0)
3636
rack-test (>= 0.6.3)
3737
rails-dom-testing (~> 2.0)
3838
rails-html-sanitizer (~> 1.0, >= 1.0.2)
39-
actionview (5.1.4)
40-
activesupport (= 5.1.4)
39+
actionview (5.2.0)
40+
activesupport (= 5.2.0)
4141
builder (~> 3.1)
4242
erubi (~> 1.4)
4343
rails-dom-testing (~> 2.0)
4444
rails-html-sanitizer (~> 1.0, >= 1.0.3)
45-
activejob (5.1.4)
46-
activesupport (= 5.1.4)
45+
activejob (5.2.0)
46+
activesupport (= 5.2.0)
4747
globalid (>= 0.3.6)
48-
activemodel (5.1.4)
49-
activesupport (= 5.1.4)
50-
activerecord (5.1.4)
51-
activemodel (= 5.1.4)
52-
activesupport (= 5.1.4)
53-
arel (~> 8.0)
54-
activesupport (5.1.4)
48+
activemodel (5.2.0)
49+
activesupport (= 5.2.0)
50+
activerecord (5.2.0)
51+
activemodel (= 5.2.0)
52+
activesupport (= 5.2.0)
53+
arel (>= 9.0)
54+
activestorage (5.2.0)
55+
actionpack (= 5.2.0)
56+
activerecord (= 5.2.0)
57+
marcel (~> 0.3.1)
58+
activesupport (5.2.0)
5559
concurrent-ruby (~> 1.0, >= 1.0.2)
56-
i18n (~> 0.7)
60+
i18n (>= 0.7, < 2)
5761
minitest (~> 5.1)
5862
tzinfo (~> 1.1)
59-
arel (8.0.0)
60-
aws-partitions (1.58.0)
61-
aws-sdk-core (3.14.0)
63+
arel (9.0.0)
64+
aws-eventstream (1.0.1)
65+
aws-partitions (1.97.0)
66+
aws-sdk-core (3.23.0)
67+
aws-eventstream (~> 1.0)
6268
aws-partitions (~> 1.0)
6369
aws-sigv4 (~> 1.0)
6470
jmespath (~> 1.0)
65-
aws-sdk-kms (1.4.0)
71+
aws-sdk-kms (1.7.0)
6672
aws-sdk-core (~> 3)
6773
aws-sigv4 (~> 1.0)
68-
aws-sdk-s3 (1.8.0)
69-
aws-sdk-core (~> 3)
74+
aws-sdk-s3 (1.17.0)
75+
aws-sdk-core (~> 3, >= 3.21.2)
7076
aws-sdk-kms (~> 1)
7177
aws-sigv4 (~> 1.0)
72-
aws-sigv4 (1.0.2)
78+
aws-sigv4 (1.0.3)
7379
builder (3.2.3)
7480
cells (4.1.7)
7581
declarative-builder (< 0.2.0)
@@ -79,89 +85,97 @@ GEM
7985
cells-haml (0.0.10)
8086
cells (>= 4.0.1, <= 6.0.0)
8187
haml (>= 4.1.0.beta.1)
82-
cells-rails (0.0.8)
88+
cells-rails (0.0.9)
8389
actionpack (>= 3.0)
8490
cells (>= 4.1.6, < 5.0.0)
8591
concurrent-ruby (1.0.5)
86-
crass (1.0.3)
92+
crass (1.0.4)
8793
declarative-builder (0.1.0)
8894
declarative-option (< 0.2.0)
8995
declarative-option (0.1.0)
90-
down (4.2.1)
91-
erubi (1.7.0)
92-
exifr (1.3.3)
93-
fastimage (2.1.1)
96+
down (4.5.0)
97+
erubi (1.7.1)
98+
exifr (1.3.4)
99+
fastimage (2.1.3)
100+
ffi (1.9.25)
94101
fspath (3.1.0)
95102
globalid (0.4.1)
96103
activesupport (>= 4.2.0)
97104
haml (5.0.4)
98105
temple (>= 0.8.0)
99106
tilt
100-
i18n (0.9.3)
107+
i18n (1.0.1)
101108
concurrent-ruby (~> 1.0)
102109
image_optim (0.26.1)
103110
exifr (~> 1.2, >= 1.2.2)
104111
fspath (~> 3.0)
105112
image_size (~> 1.5)
106113
in_threads (~> 1.3)
107114
progress (~> 3.0, >= 3.0.1)
108-
image_optim_pack (0.5.0.20180124)
115+
image_optim_pack (0.5.1)
109116
fspath (>= 2.1, < 4)
110117
image_optim (~> 0.19)
111-
image_processing (0.4.5)
118+
image_processing (1.6.0)
119+
mini_magick (~> 4.0)
120+
ruby-vips (>= 2.0.11, < 3)
112121
image_size (1.5.0)
113122
in_threads (1.5.0)
114-
jmespath (1.3.1)
123+
jmespath (1.4.0)
115124
jsonb_accessor (1.0.0)
116125
activerecord (>= 5.0)
117126
activesupport (>= 5.0)
118127
pg (>= 0.18.1)
119-
loofah (2.1.1)
128+
loofah (2.2.2)
120129
crass (~> 1.0.2)
121130
nokogiri (>= 1.5.9)
122131
mail (2.7.0)
123132
mini_mime (>= 0.1.1)
133+
marcel (0.3.2)
134+
mimemagic (~> 0.3.2)
124135
method_source (0.9.0)
125136
mimemagic (0.3.2)
126137
mini_magick (4.8.0)
127138
mini_mime (1.0.0)
128139
mini_portile2 (2.3.0)
129140
minitest (5.11.3)
130-
nio4r (2.2.0)
131-
nokogiri (1.8.2)
141+
nio4r (2.3.1)
142+
nokogiri (1.8.4)
132143
mini_portile2 (~> 2.3.0)
133144
pg (1.0.0)
134145
progress (3.4.0)
135-
rack (2.0.4)
136-
rack-test (0.8.2)
146+
rack (2.0.5)
147+
rack-test (1.1.0)
137148
rack (>= 1.0, < 3)
138-
rails (5.1.4)
139-
actioncable (= 5.1.4)
140-
actionmailer (= 5.1.4)
141-
actionpack (= 5.1.4)
142-
actionview (= 5.1.4)
143-
activejob (= 5.1.4)
144-
activemodel (= 5.1.4)
145-
activerecord (= 5.1.4)
146-
activesupport (= 5.1.4)
149+
rails (5.2.0)
150+
actioncable (= 5.2.0)
151+
actionmailer (= 5.2.0)
152+
actionpack (= 5.2.0)
153+
actionview (= 5.2.0)
154+
activejob (= 5.2.0)
155+
activemodel (= 5.2.0)
156+
activerecord (= 5.2.0)
157+
activestorage (= 5.2.0)
158+
activesupport (= 5.2.0)
147159
bundler (>= 1.3.0)
148-
railties (= 5.1.4)
160+
railties (= 5.2.0)
149161
sprockets-rails (>= 2.0.0)
150162
rails-dom-testing (2.0.3)
151163
activesupport (>= 4.2.0)
152164
nokogiri (>= 1.6)
153-
rails-html-sanitizer (1.0.3)
154-
loofah (~> 2.0)
155-
railties (5.1.4)
156-
actionpack (= 5.1.4)
157-
activesupport (= 5.1.4)
165+
rails-html-sanitizer (1.0.4)
166+
loofah (~> 2.2, >= 2.2.2)
167+
railties (5.2.0)
168+
actionpack (= 5.2.0)
169+
activesupport (= 5.2.0)
158170
method_source
159171
rake (>= 0.8.7)
160172
thor (>= 0.18.1, < 2.0)
161-
rake (12.3.0)
162-
shrine (2.9.0)
173+
rake (12.3.1)
174+
ruby-vips (2.0.12)
175+
ffi (~> 1.9)
176+
shrine (2.11.0)
163177
down (~> 4.1)
164-
sprockets (3.7.1)
178+
sprockets (3.7.2)
165179
concurrent-ruby (~> 1.0)
166180
rack (> 1, < 3)
167181
sprockets-rails (3.2.1)
@@ -175,7 +189,7 @@ GEM
175189
tzinfo (1.2.5)
176190
thread_safe (~> 0.1)
177191
uber (0.1.0)
178-
websocket-driver (0.6.5)
192+
websocket-driver (0.7.0)
179193
websocket-extensions (>= 0.1.0)
180194
websocket-extensions (0.1.3)
181195

@@ -186,4 +200,4 @@ DEPENDENCIES
186200
cortex-plugins-core!
187201

188202
BUNDLED WITH
189-
1.16.1
203+
1.16.3

app/cells/plugins/core/asset_cell.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
require 'helpers/utility_helper'
2+
13
module Plugins
24
module Core
35
class AssetCell < Plugins::Core::Cell
46
include ActionView::Helpers::NumberHelper
7+
include Cortex::Cells::AssociationHelper
58
include UtilityHelper
6-
include Cells::AssociationHelper
79

810
def input
911
render

app/transactions/get_field_tree_list_transaction.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ class GetFieldTreeListTransaction < Cortex::ApplicationTransaction
55
def init(input)
66
field = Field.find_by_id(input[:args]['field_id'])
77

8-
field ? Right({ content_item: input[:content_item], field: field }) : Left(:not_found)
8+
field ? Success({ content_item: input[:content_item], field: field }) : Failure(:not_found)
99
end
1010

1111
def process(input)
1212
tree_array = input[:field].metadata['allowed_values']['data']['tree_array']
1313
tree_values = input[:content_item].field_items.find {|field_item| field_item.field_id == input[:field].id}.data['values']
1414

1515
tree_list = tree_values.map {|value| tree_array.find {|node| node['id'] == value.to_i}['node']['name']}.join(',')
16-
Right(tree_list)
16+
Success(tree_list)
1717
end
1818
end

app/transactions/new_tag_field_item_transaction.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ class NewTagFieldItemTransaction < Cortex::ApplicationTransaction
22
step :process
33

44
def process(field_item)
5-
Right(field_item)
5+
Success(field_item)
66
end
77
end

app/transactions/new_user_field_item_transaction.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ class NewUserFieldItemTransaction < Cortex::ApplicationTransaction
22
step :process
33

44
def process(field_item)
5-
Right(field_item)
5+
Success(field_item)
66
end
77
end

app/transactions/update_tag_field_item_transaction.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ class UpdateTagFieldItemTransaction < Cortex::ApplicationTransaction
22
step :process
33

44
def process(field_item)
5-
Right(field_item)
5+
Success(field_item)
66
end
77
end
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# TODO: Refactor namespacing
2+
3+
module Plugins
4+
module Core
5+
module MediaWidgetParser
6+
def self.parse(body)
7+
body_document = document_for body
8+
9+
widget_nodes_for(body_document).each do |widget_node|
10+
widget_node.inner_html = render_widget_inner widget_node
11+
end
12+
13+
body_document.to_html
14+
end
15+
16+
def self.document_for(html)
17+
Nokogiri::HTML::DocumentFragment.parse html
18+
end
19+
20+
def self.widget_nodes_for(document)
21+
document.css 'media'
22+
end
23+
24+
def self.render_widget_inner(widget)
25+
Nokogiri::HTML::Builder.new do |doc|
26+
element, tag_type = content_item_element(widget['id'])
27+
element.merge!({ width: widget['width'], height: widget['height'], alt: widget['alt'], style: widget['style'], class: widget['class'] })
28+
29+
doc.send(tag_type, element)
30+
end.doc.root
31+
end
32+
33+
def self.content_item_element(id)
34+
asset_field_item = ContentItem.find(id).field_items.find { |field_item| field_item.field.field_type_instance.is_a?(AssetFieldType) }
35+
url = asset_field_item.data['asset']['versions']['original']['url']
36+
37+
if image? asset_field_item.data['asset']['versions']['original']['mime_type']
38+
element = { src: url }
39+
tag_type = 'img'
40+
else
41+
element = { href: url }
42+
tag_type = 'a'
43+
end
44+
45+
[element, tag_type]
46+
end
47+
48+
def self.image?(mime_type)
49+
MimeMagic.new(mime_type).mediatype == 'image'
50+
end
51+
end
52+
end
53+
end

config/initializers/tag_parsers.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cortex.tag_parsers << 'Plugins::Core::MediaWidgetParser'

0 commit comments

Comments
 (0)