editable_components 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +64 -0
- data/Rakefile +34 -0
- data/app/assets/config/editable_components_manifest.js +2 -0
- data/app/assets/fonts/editable_components/icomoon.eot +0 -0
- data/app/assets/fonts/editable_components/icomoon.svg +24 -0
- data/app/assets/fonts/editable_components/icomoon.ttf +0 -0
- data/app/assets/fonts/editable_components/icomoon.woff +0 -0
- data/app/assets/javascripts/editable_components/application.js +13 -0
- data/app/assets/javascripts/editable_components/dragula/dragula.css +22 -0
- data/app/assets/javascripts/editable_components/dragula/dragula.js +908 -0
- data/app/assets/javascripts/editable_components/dragula/dragula.min.css +1 -0
- data/app/assets/javascripts/editable_components/dragula/dragula.min.js +1 -0
- data/app/assets/javascripts/editable_components/dropzone/CONTRIBUTING.md +78 -0
- data/app/assets/javascripts/editable_components/dropzone/LICENSE +12 -0
- data/app/assets/javascripts/editable_components/dropzone/README.md +134 -0
- data/app/assets/javascripts/editable_components/dropzone/basic.css +39 -0
- data/app/assets/javascripts/editable_components/dropzone/dropzone-amd-module.js +1782 -0
- data/app/assets/javascripts/editable_components/dropzone/dropzone.css +388 -0
- data/app/assets/javascripts/editable_components/dropzone/dropzone.js +1767 -0
- data/app/assets/javascripts/editable_components/dropzone/min/basic.min.css +1 -0
- data/app/assets/javascripts/editable_components/dropzone/min/dropzone-amd-module.min.js +2 -0
- data/app/assets/javascripts/editable_components/dropzone/min/dropzone.min.css +1 -0
- data/app/assets/javascripts/editable_components/dropzone/min/dropzone.min.js +2 -0
- data/app/assets/javascripts/editable_components/main.js +280 -0
- data/app/assets/javascripts/editable_components/medium-editor/API.md +520 -0
- data/app/assets/javascripts/editable_components/medium-editor/CHANGES.md +1043 -0
- data/app/assets/javascripts/editable_components/medium-editor/CODE_OF_CONDUCT.md +13 -0
- data/app/assets/javascripts/editable_components/medium-editor/CONTRIBUTING.md +56 -0
- data/app/assets/javascripts/editable_components/medium-editor/CUSTOM-EVENTS.md +223 -0
- data/app/assets/javascripts/editable_components/medium-editor/LICENSE +36 -0
- data/app/assets/javascripts/editable_components/medium-editor/MAINTAINERS.md +33 -0
- data/app/assets/javascripts/editable_components/medium-editor/OPTIONS.md +663 -0
- data/app/assets/javascripts/editable_components/medium-editor/README.md +725 -0
- data/app/assets/javascripts/editable_components/medium-editor/UPGRADE-5.md +146 -0
- data/app/assets/javascripts/editable_components/medium-editor/medium-editor.css +230 -0
- data/app/assets/javascripts/editable_components/medium-editor/medium-editor.js +7876 -0
- data/app/assets/javascripts/editable_components/medium-editor/medium-editor.min.css +1 -0
- data/app/assets/javascripts/editable_components/medium-editor/medium-editor.min.js +4 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/beagle.css +78 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/beagle.min.css +1 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/bootstrap.css +67 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/bootstrap.min.css +1 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/default.css +63 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/default.min.css +1 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/flat.css +58 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/flat.min.css +1 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/mani.css +57 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/mani.min.css +1 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/roman.css +58 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/roman.min.css +1 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/tim.css +67 -0
- data/app/assets/javascripts/editable_components/medium-editor/themes/tim.min.css +1 -0
- data/app/assets/javascripts/editable_components/sizzle/sizzle.js +2272 -0
- data/app/assets/javascripts/editable_components/sizzle/sizzle.min.js +3 -0
- data/app/assets/javascripts/editable_components/sizzle/sizzle.min.map +1 -0
- data/app/assets/javascripts/editable_components/vue/README.md +124 -0
- data/app/assets/javascripts/editable_components/vue/vue.common.js +9320 -0
- data/app/assets/javascripts/editable_components/vue/vue.common.min.js +7 -0
- data/app/assets/javascripts/editable_components/vue/vue.esm.js +9318 -0
- data/app/assets/javascripts/editable_components/vue/vue.js +9316 -0
- data/app/assets/javascripts/editable_components/vue/vue.min.js +8 -0
- data/app/assets/javascripts/editable_components/vue/vue.runtime.common.js +6831 -0
- data/app/assets/javascripts/editable_components/vue/vue.runtime.esm.js +6829 -0
- data/app/assets/javascripts/editable_components/vue/vue.runtime.js +6827 -0
- data/app/assets/javascripts/editable_components/vue/vue.runtime.min.js +7 -0
- data/app/assets/stylesheets/editable_components/application.sass +65 -0
- data/app/assets/stylesheets/editable_components/blaze/blaze.colors.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/blaze.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.addresses.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.alerts.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.avatars.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.badges.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.breadcrumbs.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.bubbles.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.buttons.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.calendars.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.cards.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.headings.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.hints.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.input-groups.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.inputs.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.links.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.lists.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.navs.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.overlays.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.pagination.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.progress.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.ranges.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.tables.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.tabs.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.tags.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.toggles.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.tooltips.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.trees.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/components.typography.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/generics.global.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/objects.containers.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/objects.drawers.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/objects.forms.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/objects.grid.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/objects.grid.responsive.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/objects.images.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/objects.media.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/objects.modals.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/objects.panels.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/themes/blaze.example.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/utilities.alignment.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/utilities.boxing.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/utilities.elevation.min.css +1 -0
- data/app/assets/stylesheets/editable_components/blaze/utilities.sizes.min.css +1 -0
- data/app/assets/stylesheets/editable_components/dragula/dragula.css +22 -0
- data/app/assets/stylesheets/editable_components/dragula/dragula.js +908 -0
- data/app/assets/stylesheets/editable_components/dragula/dragula.min.css +1 -0
- data/app/assets/stylesheets/editable_components/dragula/dragula.min.js +1 -0
- data/app/assets/stylesheets/editable_components/main.sass +225 -0
- data/app/assets/stylesheets/editable_components/medium-editor/API.md +520 -0
- data/app/assets/stylesheets/editable_components/medium-editor/CHANGES.md +1043 -0
- data/app/assets/stylesheets/editable_components/medium-editor/CODE_OF_CONDUCT.md +13 -0
- data/app/assets/stylesheets/editable_components/medium-editor/CONTRIBUTING.md +56 -0
- data/app/assets/stylesheets/editable_components/medium-editor/CUSTOM-EVENTS.md +223 -0
- data/app/assets/stylesheets/editable_components/medium-editor/LICENSE +36 -0
- data/app/assets/stylesheets/editable_components/medium-editor/MAINTAINERS.md +33 -0
- data/app/assets/stylesheets/editable_components/medium-editor/OPTIONS.md +663 -0
- data/app/assets/stylesheets/editable_components/medium-editor/README.md +725 -0
- data/app/assets/stylesheets/editable_components/medium-editor/UPGRADE-5.md +146 -0
- data/app/assets/stylesheets/editable_components/medium-editor/medium-editor.css +230 -0
- data/app/assets/stylesheets/editable_components/medium-editor/medium-editor.js +7876 -0
- data/app/assets/stylesheets/editable_components/medium-editor/medium-editor.min.css +1 -0
- data/app/assets/stylesheets/editable_components/medium-editor/medium-editor.min.js +4 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/beagle.css +78 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/beagle.min.css +1 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/bootstrap.css +67 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/bootstrap.min.css +1 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/default.css +63 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/default.min.css +1 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/flat.css +58 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/flat.min.css +1 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/mani.css +57 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/mani.min.css +1 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/roman.css +58 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/roman.min.css +1 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/tim.css +67 -0
- data/app/assets/stylesheets/editable_components/medium-editor/themes/tim.min.css +1 -0
- data/app/controllers/editable_components/blocks_controller.rb +36 -0
- data/app/helpers/editable_components/application_helper.rb +4 -0
- data/app/jobs/editable_components/application_job.rb +4 -0
- data/app/mailers/editable_components/application_mailer.rb +6 -0
- data/app/models/editable_components/application_record.rb +5 -0
- data/app/models/editable_components/block.rb +176 -0
- data/app/models/editable_components/concerns/editable.rb +34 -0
- data/app/models/editable_components/item.rb +50 -0
- data/app/models/editable_components/item_boolean.rb +23 -0
- data/app/models/editable_components/item_datetime.rb +14 -0
- data/app/models/editable_components/item_file.rb +46 -0
- data/app/models/editable_components/item_float.rb +23 -0
- data/app/models/editable_components/item_hash.rb +16 -0
- data/app/models/editable_components/item_integer.rb +23 -0
- data/app/models/editable_components/item_string.rb +29 -0
- data/app/models/editable_components/item_text.rb +19 -0
- data/app/views/editable_components/_admin_toolbar.html.erb +105 -0
- data/app/views/editable_components/_block.html.erb +6 -0
- data/app/views/editable_components/_block_image.html.erb +6 -0
- data/app/views/editable_components/_block_multi_text.html.erb +7 -0
- data/app/views/editable_components/_block_slide.html.erb +6 -0
- data/app/views/editable_components/_block_slider.html.erb +7 -0
- data/app/views/editable_components/_block_text.html.erb +5 -0
- data/app/views/editable_components/_block_text_with_image.html.erb +12 -0
- data/app/views/editable_components/_blocks.html.erb +12 -0
- data/config/initializers/editable_components.rb +72 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20170414173603_create_editable_components_blocks.rb +18 -0
- data/db/migrate/20170414173610_create_editable_components_items.rb +11 -0
- data/db/migrate/20170414173611_add_items_booleans.rb +5 -0
- data/db/migrate/20170414173612_add_items_datetimes.rb +5 -0
- data/db/migrate/20170414173613_add_items_files.rb +5 -0
- data/db/migrate/20170414173614_add_items_floats.rb +5 -0
- data/db/migrate/20170414173615_add_items_hashes.rb +5 -0
- data/db/migrate/20170414173616_add_items_integers.rb +5 -0
- data/db/migrate/20170414173617_add_items_strings.rb +5 -0
- data/db/migrate/20170414173618_add_items_texts.rb +5 -0
- data/lib/data/img1.jpg +0 -0
- data/lib/editable_components.rb +87 -0
- data/lib/editable_components/engine.rb +21 -0
- data/lib/editable_components/version.rb +3 -0
- data/lib/tasks/editable_components_tasks.rake +4 -0
- metadata +264 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
module EditableComponents
|
2
|
+
class ItemInteger < Item
|
3
|
+
alias_attribute :data, :data_integer
|
4
|
+
|
5
|
+
def init
|
6
|
+
self.data = 0
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def update_data( value )
|
11
|
+
self.data = value.to_i
|
12
|
+
self.save
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
self.data.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.type_name
|
20
|
+
'integer'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module EditableComponents
|
2
|
+
class ItemString < Item
|
3
|
+
alias_attribute :data, :data_string
|
4
|
+
|
5
|
+
validate :on_validate
|
6
|
+
|
7
|
+
def init
|
8
|
+
self.data = self.name.gsub( /-/, ' ' ).humanize
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def on_validate
|
13
|
+
if self.block.validations[self.name]
|
14
|
+
if self.block.validations[self.name] == 'required'
|
15
|
+
self.errors.add( :base, "#{self.name} is required" ) if self.data_string.blank?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_data( value )
|
21
|
+
self.data = ActionController::Base.helpers.sanitize( value, tags: [] )
|
22
|
+
self.save
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.type_name
|
26
|
+
'string'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module EditableComponents
|
2
|
+
class ItemText < Item
|
3
|
+
alias_attribute :data, :data_text
|
4
|
+
|
5
|
+
def init
|
6
|
+
self.data = self.name.gsub( /-/, ' ' ).humanize
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def update_data( value )
|
11
|
+
self.data = ActionController::Base.helpers.sanitize( CGI.unescapeHTML( value ) )
|
12
|
+
self.save
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.type_name
|
16
|
+
'text'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
<% if EditableComponents::Engine.edit_mode && local_assigns[:page] %>
|
2
|
+
<!-- Modal dialogs -->
|
3
|
+
<div data-ec-dlg="options" class="c-overlay c-overlay--fullpage">
|
4
|
+
<div class="o-modal">
|
5
|
+
<div class="c-card">
|
6
|
+
<header class="c-card__header">
|
7
|
+
<h4 class="c-heading">Block {{ dlg_block_type }}</h4>
|
8
|
+
</header>
|
9
|
+
<div class="c-card__body">
|
10
|
+
<div v-for="block in sub_blocks" :data-ec-sub-block="block.block" :data-ec-destroy="block.destroy">
|
11
|
+
<div data-ec-dlg-buttons class="c-input-group">
|
12
|
+
<button class="c-button c-button--error" v-on:click="removeSubBlock( block.block )"><i data-ec-icon="icon-bin" title="Remove"></i></button>
|
13
|
+
<button class="c-button c-button--warning"><i data-ec-icon="icon-move-down" class="sortable" title="Move"></i></button>
|
14
|
+
</div>
|
15
|
+
<div v-for="item in block.items" is="edit-block">
|
16
|
+
<div v-if="item.input != 'file_image'" :data-ec-input="item.input" :data-ec-item="item.item" :data-ec-type="item.type" v-html="item.value"></div>
|
17
|
+
<img v-else :src="item.src" :data-ec-input="item.input" :data-ec-item="item.item" :data-ec-type="item.type" v-html="item.value"/>
|
18
|
+
</div>
|
19
|
+
</div>
|
20
|
+
<div v-for="(block, index) in new_sub_blocks" data-ec-new-sub-block>
|
21
|
+
New sub block
|
22
|
+
<button type="button" class="c-button c-button--error" v-on:click="cancelNewSubBlock(index)">
|
23
|
+
<i data-ec-icon="icon-bin"></i>
|
24
|
+
</button>
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
<footer class="c-card__footer">
|
28
|
+
<button v-show="dlg_block_container" type="button" class="c-button c-button--success" v-on:click="addSubBlock">
|
29
|
+
<i data-ec-icon="icon-plus"></i> add sub block
|
30
|
+
</button>
|
31
|
+
<button type="button" class="c-button c-button--error" v-on:click="removeBlock">
|
32
|
+
<i data-ec-icon="icon-bin"></i> remove block
|
33
|
+
</button>
|
34
|
+
<button type="button" class="c-button c-button--brand" v-on:click="dlgOptionsClose">
|
35
|
+
<i data-ec-icon="icon-floppy-disk"></i> done
|
36
|
+
</button>
|
37
|
+
</footer>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
<div data-ec-dlg="preview" class="c-overlay c-overlay--fullpage">
|
42
|
+
<div class="o-modal">
|
43
|
+
<header class="c-card__header">
|
44
|
+
<button type="button" class="c-button c-button--close" onclick="ecMain.dlgPreviewClose()">×</button>
|
45
|
+
</header>
|
46
|
+
<div class="c-card__body"></div>
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
<div data-ec-dlg="menu" class="c-overlay c-overlay--fullpage"></div>
|
50
|
+
<!-- Toolbar -->
|
51
|
+
<ul data-ec-toolbar class="c-nav c-nav--inline c-nav--fixed c-nav--bottom">
|
52
|
+
<li class="c-nav__item">
|
53
|
+
<!-- <a class="c-link" href="/admin" title="Open admin interface">Admin</a> -->
|
54
|
+
Admin
|
55
|
+
</li>
|
56
|
+
<li class="c-nav__item" onclick="ecMain.showMenu('menu-preview')">
|
57
|
+
<i data-ec-icon="icon-mobile2" title="Open preview options"></i>
|
58
|
+
<ul class="c-card c-card--menu" data-ec-menu-dropup="menu-preview">
|
59
|
+
<li class="c-card__item" onclick="ecMain.dlgPreviewOpen('mobile')">Mobile</li>
|
60
|
+
<li class="c-card__item" onclick="ecMain.dlgPreviewOpen('tablet')">Tablet</li>
|
61
|
+
</ul>
|
62
|
+
</li>
|
63
|
+
<li class="c-nav__item item-menu-add" onclick="ecMain.showMenu('menu-add');">
|
64
|
+
<i data-ec-icon="icon-plus" title="Open add options"></i>
|
65
|
+
<ul class="c-card c-card--menu" data-ec-menu-dropup="menu-add">
|
66
|
+
<% EditableComponents::Block::block_types.each do |type| %>
|
67
|
+
<li class="c-card__item" v-on:click="addBlock('<%= type %>')">New <%= type %></li>
|
68
|
+
<% end %>
|
69
|
+
</ul>
|
70
|
+
</li>
|
71
|
+
<li class="c-nav__item c-nav__item--right last-item">
|
72
|
+
<button data-edit-button class="c-button" onclick="ecMain.setEditMode()" title="Edit components"><i data-ec-icon="icon-pencil"></i> edit</button>
|
73
|
+
</li>
|
74
|
+
<% page = local_assigns[:page] %>
|
75
|
+
<% model = page.class.to_s.underscore %>
|
76
|
+
<!-- <li class="c-nav__item c-nav__item--right">
|
77
|
+
<%= form_for page, url: EditableComponents::Engine::routes.url_helpers.ec_publish_path( model, page ), method: :post, as: :ec_cmp, namespace: 'ec' do |f| %>
|
78
|
+
<input type="hidden" name="version" value="<%= @version.to_i %>"/>
|
79
|
+
<%= button_tag( type: 'submit', class: 'c-button c-button--success', title: 'Publish', 'data-ec-menu-publish': '' ) do %>
|
80
|
+
<i data-ec-icon="icon-floppy-disk"></i> publish
|
81
|
+
<% end %>
|
82
|
+
<% end %>
|
83
|
+
</li> -->
|
84
|
+
<li class="c-nav__item c-nav__item--right">
|
85
|
+
<%= form_for page, url: EditableComponents::Engine::routes.url_helpers.ec_update_path( model, page ), method: :patch, as: :ec_cmp, namespace: 'ec', html: { 'data-ec-form': '', 'data-ec-model': model, 'v-cloak': '', 'v-on:submit': 'onSubmit( $event )' } do |f| %>
|
86
|
+
<input type="hidden" name="version" value="<%= @version.to_i %>"/>
|
87
|
+
<div data-ec-fields></div>
|
88
|
+
<input v-for="input in inputs" type="hidden" v-bind:name="input.name" v-bind:value="input.value"/>
|
89
|
+
<%= button_tag( type: 'submit', class: 'c-button c-button--info', title: 'Save changes', 'data-ec-menu-save': '' ) do %>
|
90
|
+
<i data-ec-icon="icon-floppy-disk"></i> save
|
91
|
+
<% end %>
|
92
|
+
<% end %>
|
93
|
+
</li>
|
94
|
+
</ul>
|
95
|
+
<script type="text/x-template" id="ec-block-buttons-template">
|
96
|
+
<div data-ec-block-buttons class="c-input-group">
|
97
|
+
<button class="c-button c-button--brand" v-on:click="openDialogOptions">
|
98
|
+
<i data-ec-icon="icon-pencil" title="Options"></i>
|
99
|
+
</button>
|
100
|
+
<button class="c-button c-button--warning">
|
101
|
+
<i class="sortable" data-ec-icon="icon-move-down" title="Reorder"></i>
|
102
|
+
</button>
|
103
|
+
</div>
|
104
|
+
</script>
|
105
|
+
<% end %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<% block = local_assigns[:block] %>
|
2
|
+
<% if block %>
|
3
|
+
<div>
|
4
|
+
<% if block.props.image %>
|
5
|
+
<%= image_tag block.props.image.data, block.props.image.editable %>
|
6
|
+
<% end %>
|
7
|
+
<% if block.props.string %>
|
8
|
+
<div class="title"<%= block.props.string.editable %>><%== block.props.string %></div>
|
9
|
+
<div class="content"<%= block.props.text.editable %>><%== block.props.text %></div>
|
10
|
+
<% end %>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<% if local_assigns[:container] %>
|
2
|
+
<div data-ec>
|
3
|
+
<% blocks = local_assigns[:container].current_blocks( params[:version] ) %>
|
4
|
+
<% if blocks %>
|
5
|
+
<div id="ec_blocks" <%= EditableComponents::Engine.edit_mode ? "data-ec-blocks=#{blocks.length}" : '' %>><%= yield blocks %></div>
|
6
|
+
<% if EditableComponents::Engine.edit_mode %>
|
7
|
+
<div data-ec-new-blocks></div>
|
8
|
+
<% end %>
|
9
|
+
<% end %>
|
10
|
+
<%= render( partial: 'editable_components/admin_toolbar', locals: { page: local_assigns[:container] } ) %>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
@@ -0,0 +1,72 @@
|
|
1
|
+
|
2
|
+
module EditableComponents
|
3
|
+
@@config = {
|
4
|
+
ec_blocks: {
|
5
|
+
multi_text: {
|
6
|
+
children_type: :text,
|
7
|
+
name: 'Multi columns block',
|
8
|
+
items: {
|
9
|
+
column: :text
|
10
|
+
}
|
11
|
+
},
|
12
|
+
text: {
|
13
|
+
name: 'Text block',
|
14
|
+
items: {
|
15
|
+
title: :item_string,
|
16
|
+
content: :item_text
|
17
|
+
}
|
18
|
+
},
|
19
|
+
},
|
20
|
+
items: {
|
21
|
+
boolean: {},
|
22
|
+
datetime: {},
|
23
|
+
float: {},
|
24
|
+
hash: {},
|
25
|
+
file: {
|
26
|
+
input: :file_image
|
27
|
+
},
|
28
|
+
integer: {},
|
29
|
+
string: {},
|
30
|
+
text: {
|
31
|
+
input: :html
|
32
|
+
},
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
if defined? CarrierWave
|
37
|
+
@@config[:ec_blocks].merge!({
|
38
|
+
image: {
|
39
|
+
name: 'Image block',
|
40
|
+
items: {
|
41
|
+
img: :item_file
|
42
|
+
}
|
43
|
+
},
|
44
|
+
slide: {
|
45
|
+
name: 'Slide block',
|
46
|
+
items: {
|
47
|
+
img: :item_file,
|
48
|
+
title: :item_string
|
49
|
+
}
|
50
|
+
},
|
51
|
+
slider: {
|
52
|
+
children_type: :slide,
|
53
|
+
name: 'Slider block',
|
54
|
+
items: {
|
55
|
+
slide: :slide
|
56
|
+
}
|
57
|
+
},
|
58
|
+
text_with_image: {
|
59
|
+
name: 'Text with image block',
|
60
|
+
items: {
|
61
|
+
img: :item_file,
|
62
|
+
title: :item_string,
|
63
|
+
content: :item_text
|
64
|
+
}
|
65
|
+
},
|
66
|
+
})
|
67
|
+
|
68
|
+
# ItemImage.class_eval do
|
69
|
+
# mount_uploader :data, ImageUploader
|
70
|
+
# end
|
71
|
+
end
|
72
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateEditableComponentsBlocks < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :editable_components_blocks do |t|
|
4
|
+
t.string :block_type, null: false, default: 'text'
|
5
|
+
t.integer :version, null: false, default: 0
|
6
|
+
t.string :name, null: false, default: ''
|
7
|
+
t.integer :position, null: false, default: 0
|
8
|
+
t.boolean :published, null: false, default: true
|
9
|
+
t.boolean :_init, null: false, default: false
|
10
|
+
t.string :options, null: false, default: '{}'
|
11
|
+
t.string :validations, null: false, default: '{}'
|
12
|
+
t.integer :parent_id
|
13
|
+
t.string :parent_type
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :editable_components_blocks, [:parent_id, :parent_type]
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateEditableComponentsItems < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :editable_components_items do |t|
|
4
|
+
t.string :type
|
5
|
+
t.string :name, null: false, default: 'data'
|
6
|
+
t.integer :block_id
|
7
|
+
end
|
8
|
+
|
9
|
+
add_index :editable_components_items, :block_id
|
10
|
+
end
|
11
|
+
end
|
data/lib/data/img1.jpg
ADDED
Binary file
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "editable_components/engine"
|
2
|
+
|
3
|
+
module EditableComponents
|
4
|
+
def self.config( options = {} )
|
5
|
+
# p '> [TODO] EditableComponents.config'
|
6
|
+
@@config.merge! options
|
7
|
+
@@config
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.publish( parent, version )
|
11
|
+
v = version.to_i
|
12
|
+
if v > 0
|
13
|
+
v2 = Time.now.to_i
|
14
|
+
parent.ec_blocks.where( version: 0 ).update_all( version: v2 )
|
15
|
+
parent.ec_blocks.where( version: v ).update_all( version: 0 )
|
16
|
+
v2
|
17
|
+
else
|
18
|
+
v = Time.now.to_i
|
19
|
+
blocks = []
|
20
|
+
parent.ec_blocks.where( version: 0 ).each do |block|
|
21
|
+
blocks << block.amoeba_dup
|
22
|
+
blocks.last.version = v
|
23
|
+
end
|
24
|
+
parent.ec_blocks << blocks
|
25
|
+
parent.save
|
26
|
+
# TODO: delete old versions
|
27
|
+
v
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.update( parent, params )
|
32
|
+
ret = true
|
33
|
+
if params[:ec_cmp]
|
34
|
+
# TODO: return false on errors and set errors
|
35
|
+
version = params[:version].to_i
|
36
|
+
params[:ec_cmp].each do |type, fields|
|
37
|
+
model = ( 'EditableComponents::' + type ).constantize rescue nil
|
38
|
+
if model
|
39
|
+
if model.ancestors.include?( EditableComponents::Item )
|
40
|
+
# Update an item
|
41
|
+
fields.each do |k, v|
|
42
|
+
item = model.find_by_id k
|
43
|
+
if item
|
44
|
+
if !item.update_data( v )
|
45
|
+
ret = false
|
46
|
+
parent.errors.add :base, item.errors[:base]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
elsif type == 'Block'
|
51
|
+
fields.each do |k, v|
|
52
|
+
block = EditableComponents::Block.find_by_id k
|
53
|
+
if block
|
54
|
+
if v.delete( '_destroy' )
|
55
|
+
# Destroy a block
|
56
|
+
block.destroy
|
57
|
+
else
|
58
|
+
if( add = v.delete( '_add' ) )
|
59
|
+
# Create new sub blocks
|
60
|
+
t = block.block_type.to_sym
|
61
|
+
add.keys.each do
|
62
|
+
if @@config[:ec_blocks][t] && @@config[:ec_blocks][t][:children_type]
|
63
|
+
sub_block = EditableComponents::Block.new( parent: block, block_type: @@config[:ec_blocks][t][:children_type], version: version, _init: true )
|
64
|
+
sub_block.save
|
65
|
+
# TODO: return errors
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
# Update a block
|
70
|
+
block.update( v.permit( :position, :published ) )
|
71
|
+
end
|
72
|
+
elsif( add = v.delete( '_add' ) )
|
73
|
+
# Create new blocks
|
74
|
+
add.each do |index, new_type|
|
75
|
+
t = new_type.to_sym
|
76
|
+
# TODO: check if t is a valid block type
|
77
|
+
EditableComponents::Block.new( parent: parent, block_type: t, version: version, _init: true ).save
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
ret
|
86
|
+
end
|
87
|
+
end
|