effective_regions 1.8.0 → 1.8.1

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
  SHA1:
3
- metadata.gz: 1263b1785b74028263bd269c6b95e9f26511d591
4
- data.tar.gz: b93fa090047b7886802717433b1a45360cca8875
3
+ metadata.gz: 0c2c1cb3c431ab51a22dd198cd4b72f8768937cf
4
+ data.tar.gz: 1fb2b99f024b3406fecbafd4e0a9901cefb044da
5
5
  SHA512:
6
- metadata.gz: 54df70cae26e612b314fc31484ac227dd5b916a76e6f8e6770eee9a3092109e504b223f2f8a0b700571b45ff85002af96f70cb8a4809b1a417064fe1a93d5d0d
7
- data.tar.gz: 5c1819a50d38f706fae8ece1643677bb493ea03def2e468eaaaac9e22965f85875c833fab6ab59b2122608c0a4c4b8541816993b2c623eee1f00db4a3402e1ce
6
+ metadata.gz: 835fa67a7173a4aef9970b8c81004ae719bc711a7f0c5bdc458783fa1355100f01b96d91d3da8a20da4a6fff19e44338b58e0aaf47ff4b3dfbc22a50cb794647
7
+ data.tar.gz: 2b29c1d3c256c04ee3abc043aa9b2e310146f19787c49c5a12f17459f65b4b6840824d5a52f21cfb5c9667f1c787211b8118f93c741e036bbd2712cb5becf147
@@ -0,0 +1,27 @@
1
+ getCkEditorFuncNum = ->
2
+ reParam = new RegExp( '(?:[\?&]|&)' + 'CKEditorFuncNum' + '=([^&]+)', 'i' )
3
+ match = window.location.search.match(reParam)
4
+
5
+ if match && match.length > 0
6
+ match[1]
7
+
8
+ $(document).on 'click', 'a[data-insert-ck-asset]', (event) ->
9
+ ckeditor = getCkEditorFuncNum()
10
+
11
+ if ckeditor && window.opener && window.opener.CKEDITOR
12
+ event.preventDefault()
13
+
14
+ attachment = $(event.currentTarget)
15
+
16
+ url = attachment.attr('href') || attachment.attr('src')
17
+ alt = attachment.attr('alt') || ''
18
+
19
+ window.opener.CKEDITOR.tools.callFunction(ckeditor, url, ->
20
+ dialog = this.getDialog()
21
+
22
+ if dialog && dialog.getName() == 'image2'
23
+ dialog.getContentElement('info', 'alt').setValue(alt)
24
+ )
25
+
26
+ window.close()
27
+
@@ -0,0 +1,3 @@
1
+ body {
2
+ padding: 10px;
3
+ }
@@ -0,0 +1,15 @@
1
+ module Effective
2
+ class CkAssetsController < ApplicationController
3
+ layout false
4
+
5
+ include Effective::CrudController
6
+
7
+ resource_scope -> { Effective::CkAsset.all.with_attached_files }
8
+
9
+ def permitted_params
10
+ params.require(:effective_ck_asset).permit!
11
+ end
12
+
13
+ end
14
+ end
15
+
@@ -14,7 +14,7 @@ module Effective
14
14
  skip_log_page_views quiet: true, only: [:snippet] if defined?(EffectiveLogging)
15
15
 
16
16
  def edit
17
- EffectiveRegions.authorized?(self, :edit, Effective::Region.new())
17
+ EffectiveRegions.authorize!(self, :edit, Effective::Region.new)
18
18
 
19
19
  cookies['effective_regions_editting'] = {:value => params[:exit].presence || request.referrer, :path => '/'}
20
20
 
@@ -76,7 +76,7 @@ module Effective
76
76
  end
77
77
 
78
78
  def snippet # This is a GET. CKEDITOR passes us data, we need to render the non-editable content
79
- EffectiveRegions.authorized?(self, :edit, Effective::Region.new())
79
+ EffectiveRegions.authorize!(self, :edit, Effective::Region.new)
80
80
 
81
81
  klass = "Effective::Snippets::#{region_params[:name].try(:classify)}".safe_constantize
82
82
 
@@ -0,0 +1,25 @@
1
+ # This object just holds an asset file
2
+ # There is a single `global` ck asset in which we use for the ckeditor uploads form
3
+
4
+ module Effective
5
+ class CkAsset < ActiveRecord::Base
6
+ self.table_name = EffectiveRegions.ck_assets_table_name.to_s
7
+
8
+ # Only the global one
9
+ has_many_attached :files
10
+
11
+ # The instance ones will have just one file
12
+ has_one_attached :file
13
+
14
+ # Attributes
15
+ # global :boolean
16
+
17
+ def self.global
18
+ CkAsset.where(global: true).first || CkAsset.create!(global: true)
19
+ end
20
+ end
21
+ end
22
+
23
+
24
+
25
+
@@ -1,7 +1,10 @@
1
1
  module Effective
2
2
  module Snippets
3
3
  class CurrentDateTime < Snippet
4
- attribute :format, String
4
+
5
+ def snippet_attributes
6
+ super + [:format]
7
+ end
5
8
 
6
9
  def snippet_tag
7
10
  :span
@@ -1,7 +1,10 @@
1
1
  module Effective
2
2
  module Snippets
3
3
  class CurrentUserInfo < Snippet
4
- attribute :method, String
4
+
5
+ def snippet_attributes
6
+ super + [:method]
7
+ end
5
8
 
6
9
  def snippet_tag
7
10
  :span
@@ -1,18 +1,17 @@
1
- require 'virtus'
2
-
3
1
  module Effective
4
2
  module Snippets
5
3
  class Snippet
6
- include Virtus.model
7
-
8
4
  # SO I have to add some restrictions on how snippets are built:
9
5
 
10
6
  # Each Snippet has to be a block (or inline) element with nested children.
11
7
  # It has to start with a root object
12
8
  # That root object has to do {snippet_data(snippet)}
9
+ #attr_accessor :id # This will be snippet_12345
10
+ #attr_accessor :region # The region Object
13
11
 
14
- attribute :id, String # This will be snippet_12345
15
- attribute :region, Effective::Region # The region Object
12
+ def snippet_attributes
13
+ [:id, :region]
14
+ end
16
15
 
17
16
  # This is going to return all snippet objects that are saved in any Effective::Regions
18
17
  def self.all(type = nil)
@@ -59,15 +58,20 @@ module Effective
59
58
  # And it will be assigned when the effective_region is rendered
60
59
 
61
60
  def initialize(atts = {})
61
+ snippet_attributes.each { |name| self.class.send(:attr_accessor, name) }
62
62
  (atts || {}).each { |k, v| self.send("#{k}=", v) if respond_to?("#{k}=") }
63
63
  end
64
64
 
65
65
  def id
66
- super.presence || "snippet_#{object_id}"
66
+ @id || "snippet_#{object_id}"
67
+ end
68
+
69
+ def region
70
+ @region || Effective::Region.new
67
71
  end
68
72
 
69
73
  def data
70
- self.attributes.reject { |k, v| [:region, :id].include?(k) }
74
+ (self.snippet_attributes - [:region, :id]).inject({}) { |h, name| h[name] = public_send(name); h}
71
75
  end
72
76
 
73
77
  def to_partial_path
@@ -0,0 +1,7 @@
1
+ = effective_form_with(model: ck_asset, url: effective_regions.ck_asset_path(ck_asset), remote: true) do |f|
2
+ = f.hidden_field :id
3
+
4
+ = f.file_field :files, label: 'Upload file', attachments_style: :ck_assets, click_submit: true
5
+
6
+ = f.save 'Save', style: 'display: none;'
7
+
@@ -0,0 +1,19 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title Insert / Upload
5
+ %meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}
6
+ %meta{:charset => 'utf-8'}
7
+ %meta{:name => 'viewport', :content => 'width=device-width, initial-scale=1, maximum-scale=1'}
8
+
9
+ = javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js'
10
+ = javascript_include_tag 'application'
11
+ = stylesheet_link_tag 'application'
12
+
13
+ = javascript_include_tag 'ck_assets'
14
+ = stylesheet_link_tag 'ck_assets'
15
+
16
+ = csrf_meta_tags
17
+
18
+ %body
19
+ = render 'effective/ck_assets/form', ck_asset: Effective::CkAsset.global
@@ -1,5 +1,6 @@
1
1
  EffectiveRegions.setup do |config|
2
2
  config.regions_table_name = :regions
3
+ config.ck_assets_table_name = :ck_assets
3
4
 
4
5
  # Authorization Method
5
6
  #
@@ -6,6 +6,8 @@ EffectiveRegions::Engine.routes.draw do
6
6
  scope :module => 'effective' do
7
7
  scope '/effective' do
8
8
  get 'snippet/:id' => 'regions#snippet', :as => :snippet # Get a Snippet based on passed values
9
+
10
+ resources :ck_assets, only: [:index, :update] # Ckeditor IFrame
9
11
  end
10
12
 
11
13
  scope '/edit' do # Changing this, means changing the effective_ckeditor routes
@@ -12,6 +12,13 @@ class CreateEffectiveRegions < ActiveRecord::Migration[4.2]
12
12
  t.datetime :created_at
13
13
  end
14
14
 
15
+ create_table <%= @ck_assets_table_name %> do |t|
16
+ t.boolean :global, default: false
17
+
18
+ t.datetime :updated_at
19
+ t.datetime :created_at
20
+ end
21
+
15
22
  add_index <%= @regions_table_name %>, [:regionable_type, :regionable_id]
16
23
  add_index <%= @regions_table_name %>, :regionable_id
17
24
  end
@@ -1,10 +1,11 @@
1
- require 'virtus'
2
1
  require 'effective_ckeditor'
3
2
  require 'effective_regions/engine'
4
3
  require 'effective_regions/version'
5
4
 
6
5
  module EffectiveRegions
7
6
  mattr_accessor :regions_table_name
7
+ mattr_accessor :ck_assets_table_name
8
+
8
9
  mattr_accessor :authorization_method
9
10
  mattr_accessor :before_save_method
10
11
 
@@ -13,10 +14,20 @@ module EffectiveRegions
13
14
  end
14
15
 
15
16
  def self.authorized?(controller, action, resource)
16
- if authorization_method.respond_to?(:call) || authorization_method.kind_of?(Symbol)
17
- raise Effective::AccessDenied.new() unless (controller || self).instance_exec(controller, action, resource, &authorization_method)
17
+ @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
18
+
19
+ return !!authorization_method unless authorization_method.respond_to?(:call)
20
+ controller = controller.controller if controller.respond_to?(:controller)
21
+
22
+ begin
23
+ !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
24
+ rescue *@_exceptions
25
+ false
18
26
  end
19
- true
27
+ end
28
+
29
+ def self.authorize!(controller, action, resource)
30
+ raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
20
31
  end
21
32
 
22
33
  # Returns a Snippet.new() for every class in the /app/effective/snippets/* directory
@@ -23,5 +23,9 @@ module EffectiveRegions
23
23
  eval File.read("#{config.root}/config/effective_regions.rb")
24
24
  end
25
25
 
26
+ initializer "effective_regions.append_precompiled_assets" do |app|
27
+ Rails.application.config.assets.precompile += ['ck_assets.js', 'ck_assets.css']
28
+ end
29
+
26
30
  end
27
31
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveRegions
2
- VERSION = '1.8.0'.freeze
2
+ VERSION = '1.8.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_regions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: virtus
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  description: Create editable content regions within your existing, ordinary ActionView::Base
56
42
  views, and update content with an actually-good full-screen WYSIWYG editor.
57
43
  email:
@@ -64,13 +50,17 @@ files:
64
50
  - README.md
65
51
  - Rakefile
66
52
  - app/assets/images/effective/templates/image_and_title.png
53
+ - app/assets/javascripts/ck_assets.js.coffee
67
54
  - app/assets/javascripts/effective/snippets/current_date_time.js.coffee
68
55
  - app/assets/javascripts/effective/snippets/current_user_info.js.coffee
56
+ - app/assets/stylesheets/ck_assets.scss
57
+ - app/controllers/effective/ck_assets_controller.rb
69
58
  - app/controllers/effective/regions_controller.rb
70
59
  - app/helpers/effective_regions_controller_helper.rb
71
60
  - app/helpers/effective_regions_helper.rb
72
61
  - app/models/concerns/acts_as_regionable.rb
73
62
  - app/models/effective/access_denied.rb
63
+ - app/models/effective/ck_asset.rb
74
64
  - app/models/effective/region.rb
75
65
  - app/models/effective/snippets/current_date_time.rb
76
66
  - app/models/effective/snippets/current_user_info.rb
@@ -79,6 +69,8 @@ files:
79
69
  - app/models/effective/templates/template.rb
80
70
  - app/models/effective/templates/three_column.rb
81
71
  - app/models/effective/templates/two_column.rb
72
+ - app/views/effective/ck_assets/_form.html.haml
73
+ - app/views/effective/ck_assets/index.html.haml
82
74
  - app/views/effective/snippets/_current_date_time.html.haml
83
75
  - app/views/effective/snippets/_current_user_info.html.haml
84
76
  - app/views/effective/templates/_image_and_title.html.haml