promethee 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +53 -50
  3. data/app/assets/javascripts/promethee-editor.js +8 -0
  4. data/app/assets/javascripts/promethee.js +0 -59
  5. data/app/assets/stylesheets/promethee-editor.sass +23 -78
  6. data/app/assets/stylesheets/promethee-editor/_component.sass +10 -0
  7. data/app/assets/stylesheets/promethee-editor/_mover.sass +67 -0
  8. data/app/assets/stylesheets/promethee-editor/_preview.sass +25 -0
  9. data/app/assets/stylesheets/promethee.sass +1 -2
  10. data/app/controllers/promethee_controller.rb +8 -0
  11. data/app/views/promethee/_edit.html.erb +52 -123
  12. data/app/views/promethee/_show.html.erb +1 -1
  13. data/app/views/promethee/components/_children.html.erb +4 -0
  14. data/app/views/promethee/components/_children_edit.html.erb +5 -0
  15. data/app/views/promethee/components/_column.html.erb +1 -1
  16. data/app/views/promethee/components/_column_edit.html.erb +35 -33
  17. data/app/views/promethee/components/_image_edit.html.erb +23 -28
  18. data/app/views/promethee/components/_page.html.erb +1 -0
  19. data/app/views/promethee/components/_page_edit.html.erb +10 -0
  20. data/app/views/promethee/components/_row.html.erb +1 -4
  21. data/app/views/promethee/components/_row_edit.html.erb +19 -22
  22. data/app/views/promethee/components/_text_edit.html.erb +16 -20
  23. data/app/views/promethee/components/_video_edit.html.erb +23 -22
  24. data/app/views/promethee/partials/_adder.html.erb +64 -0
  25. data/app/views/promethee/partials/_include_components.html.erb +9 -0
  26. data/app/views/promethee/partials/_mover.html.erb +98 -0
  27. data/app/views/promethee/partials/_navbar.html.erb +26 -0
  28. data/app/views/promethee/partials/_page.html.erb +6 -0
  29. data/app/views/promethee/partials/_preview.html.erb +12 -0
  30. data/app/views/promethee/partials/_toolbar_buttons.html.erb +2 -2
  31. data/app/views/promethee/preview.html.erb +1 -0
  32. data/config/routes.rb +3 -0
  33. data/lib/promethee.rb +2 -21
  34. data/lib/promethee/core_ext/tags.rb +2 -5
  35. data/lib/promethee/rails/version.rb +1 -1
  36. metadata +34 -27
  37. data/app/assets/javascripts/promethee/controller.js +0 -22
  38. data/app/assets/stylesheets/promethee-editor/_mixins.sass +0 -19
  39. data/app/assets/stylesheets/promethee-editor/_variables.sass +0 -4
  40. data/app/views/promethee/components/_index.html.erb +0 -3
  41. data/app/views/promethee/components/_index_edit.html.erb +0 -7
  42. data/app/views/promethee/components/_show.html.erb +0 -4
  43. data/app/views/promethee/components/_show_edit.html.erb +0 -3
  44. data/lib/promethee/component.rb +0 -28
  45. data/lib/promethee/component/attribute.rb +0 -42
  46. data/lib/promethee/component/attribute/boolean.rb +0 -4
  47. data/lib/promethee/component/attribute/float.rb +0 -3
  48. data/lib/promethee/component/attribute/integer.rb +0 -3
  49. data/lib/promethee/component/attribute/string.rb +0 -3
  50. data/lib/promethee/component/attributes.rb +0 -50
  51. data/lib/promethee/component/attributes/definer.rb +0 -13
  52. data/lib/promethee/component/base.rb +0 -68
  53. data/lib/promethee/component/collection.rb +0 -17
  54. data/lib/promethee/component/column.rb +0 -8
  55. data/lib/promethee/component/image.rb +0 -6
  56. data/lib/promethee/component/row.rb +0 -3
  57. data/lib/promethee/component/text.rb +0 -5
  58. data/lib/promethee/component/video.rb +0 -5
  59. data/lib/promethee/grid.rb +0 -52
  60. data/vendor/assets/javascripts/angular-drag-and-drop-lists.js +0 -49
@@ -1,22 +0,0 @@
1
- Promethee.Controller = function(name, initializer) {
2
- this.name = name;
3
- this.initializer = initializer;
4
- };
5
-
6
- Promethee.Controller.prototype = {
7
- constructor: Promethee.Controller,
8
-
9
- initialize: function(promethee) {
10
- promethee.app.controller(this.name, this.initializer);
11
- }
12
- };
13
-
14
- Promethee.Controller.controllers = {};
15
-
16
- Promethee.Controller.for = function(name, initializer) {
17
- this.controllers[name] = new this(name, initializer);
18
- };
19
-
20
- Promethee.Controller.initialize = function(promethee) {
21
- for(var name in this.controllers) this.controllers[name].initialize(promethee);
22
- };
@@ -1,19 +0,0 @@
1
- =grid-builder-set-gutter-width($width)
2
- $was: $grid-gutter-width
3
- $grid-gutter-width: $width !global
4
-
5
- .row
6
- +make-row
7
-
8
- +make-grid-columns
9
- +make-grid(xs)
10
- @media(min-width: 768px)
11
- +make-grid(sm)
12
-
13
- @media (min-width: 992px)
14
- +make-grid(md)
15
-
16
- @media (min-width: 1200px)
17
- +make-grid(lg)
18
-
19
- $grid-gutter-width: $was !global
@@ -1,4 +0,0 @@
1
- $promethee-grey: #bbb
2
- $promethee-transparent-grey: transparentize($promethee-grey, .8)
3
-
4
- $promethee-light-grey: #eee
@@ -1,3 +0,0 @@
1
- <% components.each do |component| %>
2
- <%= render partial: 'promethee/components/show', locals: { component: component } %>
3
- <% end %>
@@ -1,7 +0,0 @@
1
- <script type="text/ng-template" id="promethee/components/index">
2
- <div class="promethee-editor__components" ng-init="components = component.children" dnd-list="components" dnd-allowed-types="allowedTypes">
3
- <div ng-repeat="component in components">
4
- <ng-include src="'promethee/components/show'"></ng-include>
5
- </div>
6
- </div>
7
- </script>
@@ -1,4 +0,0 @@
1
- <%
2
- type = component[:type]
3
- %>
4
- <%= render partial: "promethee/components/#{type}", locals: { component: component } %>
@@ -1,3 +0,0 @@
1
- <script type="text/ng-template" id="promethee/components/show">
2
- <ng-include src="'promethee/components/' + component.type"></ng-include>
3
- </script>
@@ -1,28 +0,0 @@
1
- module Promethee::Component
2
- def self.types
3
- Base.descendants.map &:type
4
- end
5
-
6
- def self.as type
7
- begin
8
- class_name = "::Promethee::Component::#{type.to_s.classify}"
9
- require "promethee/component/#{type}" unless Object.const_defined? class_name
10
- class_name.constantize
11
- rescue LoadError
12
- raise "Unknown Prométhée component type \"#{type}\". Available types: \"#{types.join '", "'}\"."
13
- end
14
- end
15
-
16
- def self.from data
17
- raise "Invalid data provided, expected a Hash got a #{data.class}." unless data.is_a? Hash
18
-
19
- data = data.deep_dup
20
-
21
- data[:attributes] = {} unless data[:attributes].is_a? Hash
22
- data[:children] = [] unless data[:children].is_a? Array
23
-
24
- data[:children].map! { |data| from data }
25
-
26
- as(data[:type]).new attributes: data[:attributes], children: data[:children]
27
- end
28
- end
@@ -1,42 +0,0 @@
1
- module Promethee::Component::Attribute
2
- class Base
3
- attr_reader :name, :value
4
-
5
- def initialize name, value = default
6
- @name = name.to_s.to_sym
7
- self.value = value
8
- end
9
-
10
- def value= value
11
- @value = value == default ? default : cast(value)
12
- end
13
-
14
- def default
15
- self.class.default
16
- end
17
-
18
- def cast value
19
- self.class.cast.call value
20
- end
21
-
22
- def dup
23
- self.class.new name, (value.dup rescue value)
24
- end
25
-
26
- private
27
-
28
- def self.type
29
- to_s.split('::').last.underscore
30
- end
31
-
32
- def self.default value = nil
33
- @value = value unless value.nil?
34
- @value
35
- end
36
-
37
- def self.cast &block
38
- @cast = block if block_given?
39
- @cast ||= -> (value) { value }
40
- end
41
- end
42
- end
@@ -1,4 +0,0 @@
1
- class Promethee::Component::Attribute::Boolean < Promethee::Component::Attribute::Base
2
- default false
3
- cast { |value| !!value }
4
- end
@@ -1,3 +0,0 @@
1
- class Promethee::Component::Attribute::Float < Promethee::Component::Attribute::Base
2
- cast { |value| value&.to_f or default }
3
- end
@@ -1,3 +0,0 @@
1
- class Promethee::Component::Attribute::Integer < Promethee::Component::Attribute::Base
2
- cast { |value| value&.to_i or default }
3
- end
@@ -1,3 +0,0 @@
1
- class Promethee::Component::Attribute::String < Promethee::Component::Attribute::Base
2
- cast { |value| value&.to_s or default }
3
- end
@@ -1,50 +0,0 @@
1
- class Promethee::Component::Attributes
2
- def update hash
3
- (names & hash.keys.map(&:to_sym)).each { |name| attributes[name].value = hash[name] }
4
-
5
- self
6
- end
7
-
8
- def to_hash
9
- attributes.map{ |name, attribute| [name, attribute.value] }.to_h
10
- end
11
- alias_method :to_h, :to_hash
12
- alias_method :as_json, :to_hash
13
-
14
- def [](method)
15
- send method
16
- end
17
-
18
- def keys
19
- attributes.keys
20
- end
21
- alias_method :names, :keys
22
-
23
- def each &block
24
- attributes.values.each &block
25
- end
26
-
27
- def << attribute
28
- attributes[attribute.name] = attribute
29
-
30
- define_singleton_method(attribute.name) { attribute.value }
31
- define_singleton_method("#{attribute.name}=") { |value| attribute.value = value }
32
- end
33
-
34
- def dup
35
- duplicate = self.class.new
36
- each { |attribute| duplicate << attribute.dup }
37
-
38
- duplicate
39
- end
40
-
41
- def copy hash
42
- dup.update hash
43
- end
44
-
45
- private
46
-
47
- def attributes
48
- @attributes ||= {}
49
- end
50
- end
@@ -1,13 +0,0 @@
1
- class Promethee::Component::Attributes::Definer
2
- attr_reader :component
3
-
4
- def initialize(component)
5
- @component = component
6
- end
7
-
8
- ::Promethee::Component::Attribute::Base.descendants.each do |attribute|
9
- define_method attribute.type do |name, default: nil|
10
- component.attributes << attribute.new(name, default)
11
- end
12
- end
13
- end
@@ -1,68 +0,0 @@
1
- class Promethee::Component::Base
2
- attr_reader :attributes, :children
3
-
4
- def initialize(attributes: {}, children: [])
5
- @attributes = self.class.attributes.copy attributes
6
- @children = Promethee::Component::Collection.new children
7
- end
8
-
9
- def to_hash *options
10
- {
11
- type: type,
12
- attributes: attributes.to_hash,
13
- children: children.to_ary
14
- }
15
- end
16
- alias_method :to_h, :to_hash
17
- alias_method :as_json, :to_hash
18
-
19
- def to_html
20
- ApplicationController.renderer.render partial: "promethee/components/#{type}", locals: { component: self }
21
- end
22
-
23
- def [](method)
24
- send method
25
- end
26
-
27
- def class_name
28
- "promethee__component promethee__component--#{type}"
29
- end
30
-
31
- def type
32
- self.class.type
33
- end
34
-
35
- def self.attributes
36
- @attributes ||= Promethee::Component::Attributes.new
37
- end
38
-
39
- def self.children
40
- @children ||= []
41
- end
42
-
43
- def self.type
44
- to_s.split('::').last.underscore.to_sym
45
- end
46
-
47
- def self.final?
48
- children.empty?
49
- end
50
-
51
- # def self.class_name
52
- # "promethee-editor__component promethee__component--#{type}#{' promethee__component--final' if final?}"
53
- # end
54
-
55
- private
56
-
57
- def self.has_attributes
58
- yield Promethee::Component::Attributes::Definer.new(self) if block_given?
59
- end
60
-
61
- def self.has_children *components
62
- children.concat(components.flatten.map{ |component| component.is_a?(Class) && component < self ? component : Promethee::Component.as(component) }).uniq!
63
- end
64
-
65
- class << self
66
- alias_method :has_child, :has_children
67
- end
68
- end
@@ -1,17 +0,0 @@
1
- class Promethee::Component::Collection < Array
2
- def to_ary
3
- map &:to_hash
4
- end
5
- alias_method :to_a, :to_ary
6
- alias_method :as_json, :to_ary
7
-
8
- def to_html
9
- map(&:to_html).join.html_safe
10
- end
11
-
12
- def self.from data
13
- raise "Invalid data provided, expected a Array got a #{data.class}." unless data.is_a? Array
14
-
15
- new data.map{ |component| Promethee::Component.from component }
16
- end
17
- end
@@ -1,8 +0,0 @@
1
- class Promethee::Component::Column < Promethee::Component::Base
2
- has_attributes do |a|
3
- a.integer :size, default: 4
4
- a.integer :offset, default: 0
5
- end
6
-
7
- has_children :row, :text, :image, :video
8
- end
@@ -1,6 +0,0 @@
1
- class Promethee::Component::Image < Promethee::Component::Base
2
- has_attributes do |a|
3
- a.string :src
4
- a.string :alt
5
- end
6
- end
@@ -1,3 +0,0 @@
1
- class Promethee::Component::Row < Promethee::Component::Base
2
- has_child :column
3
- end
@@ -1,5 +0,0 @@
1
- class Promethee::Component::Text < Promethee::Component::Base
2
- has_attributes do |a|
3
- a.string :body, default: ''
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class Promethee::Component::Video < Promethee::Component::Base
2
- has_attributes do |a|
3
- a.string :url
4
- end
5
- end
@@ -1,52 +0,0 @@
1
- class Promethee::Grid
2
- include ActionView::Helpers::FormTagHelper
3
-
4
- attr_accessor :data, :name, :id
5
-
6
- def initialize(data = [], name: nil, id: nil)
7
- self.data = data
8
- self.name = name
9
- self.id = id.nil? ? self.class.id : id
10
- end
11
-
12
- def components
13
- Promethee::Component::Collection.from data
14
- end
15
-
16
- # def value
17
- # data.is_a?(String) ? data : data.to_json
18
- # end
19
-
20
- def input options = {}
21
- hidden_field_tag name, '{{promethee.data}}', options
22
- end
23
-
24
- # def to_javascript
25
- # <<-JAVASCRIPT.html_safe
26
- # new Promethee(#{id.to_json}, #{data.to_json})
27
- # JAVASCRIPT
28
- # end
29
- # alias_method :to_js, :to_javascript
30
-
31
- def template(type)
32
- ApplicationController.renderer.render partial: "/promethee/#{'components/' unless [:component, :components].include? type.to_s.to_sym }#{type}_edit", locals: { promethee: self }
33
- end
34
-
35
- def templates
36
- Promethee::Component.types.map{ |type| template type }.join.html_safe
37
- end
38
-
39
- def edit
40
- ApplicationController.renderer.render partial: 'promethee/edit', locals: { promethee: self }
41
- end
42
-
43
- def show
44
- ApplicationController.renderer.render partial: 'promethee/show', locals: { promethee: self }
45
- end
46
-
47
- private
48
-
49
- def self.id
50
- "promethee-#{SecureRandom.hex 10}"
51
- end
52
- end
@@ -1,49 +0,0 @@
1
- /**
2
- * angular-drag-and-drop-lists v2.1.0
3
- *
4
- * Copyright (c) 2014 Marcel Juenemann marcel@juenemann.cc
5
- * Copyright (c) 2014-2017 Google Inc.
6
- * https://github.com/marceljuenemann/angular-drag-and-drop-lists
7
- *
8
- * License: MIT
9
- */
10
- !function(e){function n(e,n){return"all"==n?e:e.filter(function(e){return-1!=n.toLowerCase().indexOf(e)})}var a="application/x-dnd",r="application/json",t="Text",d=["move","copy","link"]
11
- e.directive("dndDraggable",["$parse","$timeout",function(e,i){return function(l,f,c){f.attr("draggable","true"),c.dndDisableIf&&l.$watch(c.dndDisableIf,function(e){f.attr("draggable",!e)}),f.on("dragstart",function(s){if(s=s.originalEvent||s,"false"==f.attr("draggable"))return!0
12
- o.isDragging=!0,o.itemType=c.dndType&&l.$eval(c.dndType).toLowerCase(),o.dropEffect="none",o.effectAllowed=c.dndEffectAllowed||d[0],s.dataTransfer.effectAllowed=o.effectAllowed
13
- var g=l.$eval(c.dndDraggable),u=a+(o.itemType?"-"+o.itemType:"")
14
- try{s.dataTransfer.setData(u,angular.toJson(g))}catch(p){var v=angular.toJson({item:g,type:o.itemType})
15
- try{s.dataTransfer.setData(r,v)}catch(p){var D=n(d,o.effectAllowed)
16
- s.dataTransfer.effectAllowed=D[0],s.dataTransfer.setData(t,v)}}if(f.addClass("dndDragging"),i(function(){f.addClass("dndDraggingSource")},0),s._dndHandle&&s.dataTransfer.setDragImage&&s.dataTransfer.setDragImage(f[0],0,0),e(c.dndDragstart)(l,{event:s}),c.dndCallback){var y=e(c.dndCallback)
17
- o.callback=function(e){return y(l,e||{})}}s.stopPropagation()}),f.on("dragend",function(n){n=n.originalEvent||n,l.$apply(function(){var a=o.dropEffect,r={copy:"dndCopied",link:"dndLinked",move:"dndMoved",none:"dndCanceled"}
18
- e(c[r[a]])(l,{event:n}),e(c.dndDragend)(l,{event:n,dropEffect:a})}),o.isDragging=!1,o.callback=void 0,f.removeClass("dndDragging"),f.removeClass("dndDraggingSource"),n.stopPropagation(),i(function(){f.removeClass("dndDraggingSource")},0)}),f.on("click",function(n){c.dndSelected&&(n=n.originalEvent||n,l.$apply(function(){e(c.dndSelected)(l,{event:n})}),n.stopPropagation())}),f.on("selectstart",function(){this.dragDrop&&this.dragDrop()})}}]),e.directive("dndList",["$parse",function(e){return function(i,l,f){function c(e){if(!e)return t
19
- for(var n=0;n<e.length;n++)if(e[n]==t||e[n]==r||e[n].substr(0,a.length)==a)return e[n]
20
- return null}function s(e){return o.isDragging?o.itemType||void 0:e==t||e==r?null:e&&e.substr(a.length+1)||void 0}function g(e){return E.disabled?!1:E.externalSources||o.isDragging?E.allowedTypes&&null!==e?e&&-1!=E.allowedTypes.indexOf(e):!0:!1}function u(e,a){var r=d
21
- return a||(r=n(r,e.dataTransfer.effectAllowed)),o.isDragging&&(r=n(r,o.effectAllowed)),f.dndEffectAllowed&&(r=n(r,f.dndEffectAllowed)),r.length?e.ctrlKey&&-1!=r.indexOf("copy")?"copy":e.altKey&&-1!=r.indexOf("link")?"link":r[0]:"none"}function p(){return T.remove(),l.removeClass("dndDragover"),!0}function v(n,a,r,t,d,l){return e(n)(i,{callback:o.callback,dropEffect:r,event:a,external:!o.isDragging,index:void 0!==d?d:D(),item:l||void 0,type:t})}function D(){return Array.prototype.indexOf.call(m.children,h)}function y(){var e
22
- return angular.forEach(l.children(),function(n){var a=angular.element(n)
23
- a.hasClass("dndPlaceholder")&&(e=a)}),e||angular.element("<li class='dndPlaceholder'></li>")}var T=y()
24
- T.remove()
25
- var h=T[0],m=l[0],E={}
26
- l.on("dragenter",function(e){e=e.originalEvent||e
27
- var n=f.dndAllowedTypes&&i.$eval(f.dndAllowedTypes)
28
- E={allowedTypes:angular.isArray(n)&&n.join("|").toLowerCase().split("|"),disabled:f.dndDisableIf&&i.$eval(f.dndDisableIf),externalSources:f.dndExternalSources&&i.$eval(f.dndExternalSources),horizontal:f.dndHorizontalList&&i.$eval(f.dndHorizontalList)}
29
- var a=c(e.dataTransfer.types)
30
- return a&&g(s(a))?void e.preventDefault():!0}),l.on("dragover",function(e){e=e.originalEvent||e
31
- var n=c(e.dataTransfer.types),a=s(n)
32
- if(!n||!g(a))return!0
33
- if(h.parentNode!=m&&l.append(T),e.target!=m){for(var r=e.target;r.parentNode!=m&&r.parentNode;)r=r.parentNode
34
- if(r.parentNode==m&&r!=h){var d=r.getBoundingClientRect()
35
- if(E.horizontal)var o=e.clientX<d.left+d.width/2
36
- else var o=e.clientY<d.top+d.height/2
37
- m.insertBefore(h,o?r:r.nextSibling)}}var i=n==t,D=u(e,i)
38
- return"none"==D?p():f.dndDragover&&!v(f.dndDragover,e,D,a)?p():(e.preventDefault(),i||(e.dataTransfer.dropEffect=D),l.addClass("dndDragover"),e.stopPropagation(),!1)}),l.on("drop",function(e){e=e.originalEvent||e
39
- var n=c(e.dataTransfer.types),a=s(n)
40
- if(!n||!g(a))return!0
41
- e.preventDefault()
42
- try{var d=JSON.parse(e.dataTransfer.getData(n))}catch(l){return p()}if((n==t||n==r)&&(a=d.type||void 0,d=d.item,!g(a)))return p()
43
- var y=n==t,T=u(e,y)
44
- if("none"==T)return p()
45
- var h=D()
46
- return f.dndDrop&&(d=v(f.dndDrop,e,T,a,h,d),!d)?p():(o.dropEffect=T,y||(e.dataTransfer.dropEffect=T),d!==!0&&i.$apply(function(){i.$eval(f.dndList).splice(h,0,d)}),v(f.dndInserted,e,T,a,h,d),p(),e.stopPropagation(),!1)}),l.on("dragleave",function(e){e=e.originalEvent||e
47
- var n=document.elementFromPoint(e.clientX,e.clientY)
48
- m.contains(n)&&!e._dndPhShown?e._dndPhShown=!0:p()})}}]),e.directive("dndNodrag",function(){return function(e,n,a){n.attr("draggable","true"),n.on("dragstart",function(e){e=e.originalEvent||e,e._dndHandle||(e.dataTransfer.types&&e.dataTransfer.types.length||e.preventDefault(),e.stopPropagation())}),n.on("dragend",function(e){e=e.originalEvent||e,e._dndHandle||e.stopPropagation()})}}),e.directive("dndHandle",function(){return function(e,n,a){n.attr("draggable","true"),n.on("dragstart dragend",function(e){e=e.originalEvent||e,e._dndHandle=!0})}})
49
- var o={}}(angular.module("dndLists",[]));