simplec 0.2.0 → 0.3.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
  SHA1:
3
- metadata.gz: cc12728b3f36924c9748feeaf9b913adf6f2f4c5
4
- data.tar.gz: acf72f1d1f5116208a044018df7e50ca298f458e
3
+ metadata.gz: cd4562c8c0bbab684b813215b25a37647dbbd134
4
+ data.tar.gz: 924e595fdddaf414fcbd91a33b0a5008e7913864
5
5
  SHA512:
6
- metadata.gz: d7bd9cd9bc1007492113fc583e5c3eca2023938f6ab50f326e2f2ea194c946d24ec6bc5fe06aee34c88722f13ba8da53751282c8e233fb9e8fa21ea0ed190634
7
- data.tar.gz: 0fb75e9fa2898854726b89dca64b5c3c610059835c5eecbf2dad81c53fd6aa3cd1a7f8e9071536b7edf59f8aa805ed57eec1644ec75d79bfde4833ab85a35b7f
6
+ metadata.gz: 49b55b0d7c216b7e35a5cec8f8c2e99086077dfd43ad5f27d9da0e6de3446b62e51a06013b2fc707554a5888cfcb3b69cfa5947d51f73a9e7718775a18f9c8a5
7
+ data.tar.gz: 6ce855a1ca1486f9e302dab3bf1b8c69cc8137c85cefd84daf1e14794658f35bd5a41f4f427d3031820d49e205833ddeb84c0fe9335460ba202630fa5c7ca7f3
data/README.md CHANGED
@@ -244,10 +244,11 @@ See this page for a good cheat sheet: http://markevans.github.io/dragonfly/image
244
244
 
245
245
  1. TODOS:
246
246
 
247
- - Embedded image id (integer -> uuid)
248
-
249
247
  - Check doc view helpers
250
248
 
249
+ - Add config options for uuid vs integer ids, maybe check if page is using
250
+ uuid/id if table exists to determine going forward. Add note in README
251
+
251
252
  - Throw clear warning when creating a page without a type
252
253
 
253
254
  - Document `lib/simplec/controller_extensions.rb`
@@ -260,6 +261,8 @@ See this page for a good cheat sheet: http://markevans.github.io/dragonfly/image
260
261
 
261
262
  - rewrite beginning part of usage
262
263
 
264
+ - utilize thread local variable for found subdomain in #subdomain
265
+
263
266
  - simplec_path/simplec_url caching
264
267
 
265
268
  1. Installer `rails generater simplec:install`
@@ -52,6 +52,7 @@ window.simplec.initSummernote = function() {
52
52
  url: '/embedded-images',
53
53
  dataType: 'json',
54
54
  contentType: 'application/json',
55
+ headers: { 'X-Engine': 'simplec' },
55
56
  data: JSON.stringify({
56
57
  asset_url: reader.result,
57
58
  asset_name: file.name
@@ -1,23 +1,29 @@
1
1
  module Simplec
2
2
  class Subdomains
3
- def self.matches?(request)
3
+ def self.matches?(request)
4
+ simplec = request.headers['HTTP_X_ENGINE'] == 'simplec'
4
5
  present = request.subdomain.present?
5
- not_admin = request.subdomain != 'admin'
6
- subdomain = Simplec::Subdomain.find_by(name: request.subdomain)
6
+ not_admin = request.subdomain != 'admin'
7
+ subdomain = Simplec::Subdomain.find_by(name: request.subdomain)
7
8
 
8
- match = present && not_admin && subdomain
9
+ match = simplec || (present && not_admin && subdomain)
9
10
 
10
11
  if match
11
12
  Thread.current[:simplec_subdomain] = subdomain
13
+ Rails.logger.info <<-LOG
14
+ Simplec request received.
15
+ ActionDispatch::Request#original_url: #{request.original_url}
16
+ Simplec Engine: #{not_admin}
17
+ LOG
12
18
  else
13
- Rails.logger.info <<-LOG unless match
19
+ Rails.logger.info <<-LOG
14
20
  Simplec Subdomain '#{request.subdomain}' was not found.
15
21
  ActionDispatch::Request#original_url: #{request.original_url}
16
22
  'admin' subdomain bypass: #{!not_admin}
17
- LOG
23
+ LOG
18
24
  end
19
25
 
20
- match
21
- end
26
+ match
27
+ end
22
28
  end
23
29
  end
@@ -0,0 +1,7 @@
1
+ require_dependency "simplec/application_controller"
2
+
3
+ module Simplec
4
+ class EmbeddedImagesController < ApplicationController
5
+ include Simplec::EmbeddedImageActions
6
+ end
7
+ end
@@ -1,7 +1,8 @@
1
1
  module Simplec
2
2
  class EmbeddedImage < ApplicationRecord
3
3
  belongs_to :embeddable,
4
- polymorphic: true
4
+ polymorphic: true,
5
+ optional: true
5
6
 
6
7
  dragonfly_accessor :asset
7
8
 
@@ -10,6 +11,7 @@ module Simplec
10
11
  return self.asset.url unless persisted?
11
12
  self.asset.url(ei: Base64.urlsafe_encode64(self.id.to_s))
12
13
  end
14
+ alias_method :asset_url, :url
13
15
 
14
16
  end
15
17
  end
data/config/routes.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  Simplec::Engine.routes.draw do
2
2
 
3
3
  scope constraints: Simplec::Subdomains do
4
+ resources :embedded_images, path: 'embedded-images', only: :create
4
5
  root 'pages#show'
5
6
  get '*path', to: 'pages#show'
6
7
  end
@@ -2,7 +2,7 @@ class CreateSimplecEmbeddedImages < ActiveRecord::Migration[5.0]
2
2
  def change
3
3
  create_table :simplec_embedded_images, id: :uuid, default: 'gen_random_uuid()' do |t|
4
4
  t.string :embeddable_type
5
- t.integer :embeddable_id
5
+ t.uuid :embeddable_id
6
6
  t.string :asset_uid
7
7
  t.string :asset_name
8
8
 
@@ -4,28 +4,29 @@ module Simplec
4
4
 
5
5
  module InstanceMethods
6
6
 
7
- def create
8
- @embedded_image = EmbeddedImage.new(embedded_image_params)
9
- if @embedded_image.save
10
- respond_to do |format|
11
- format.json {
12
- render :show, status: 201, location: @embedded_image.url
13
- }
14
- end
15
- else
16
- respond_to do |format|
17
- format.json {
18
- render status: 422, json: @embedded_image.errors
19
- }
20
- end
21
- end
22
- end
7
+ def create
8
+ @embedded_image = EmbeddedImage.new(embedded_image_params)
9
+ if @embedded_image.save
10
+ respond_to do |format|
11
+ format.json {
12
+ render status: 201, location: @embedded_image.url,
13
+ json: @embedded_image.slice(:id, :asset_name, :asset_url)
14
+ }
15
+ end
16
+ else
17
+ respond_to do |format|
18
+ format.json {
19
+ render status: 422, json: @embedded_image.errors
20
+ }
21
+ end
22
+ end
23
+ end
23
24
 
24
- private
25
+ private
25
26
 
26
- def embedded_image_params
27
- params.permit(:asset_url, :asset_name)
28
- end
27
+ def embedded_image_params
28
+ params.permit(:asset_url, :asset_name)
29
+ end
29
30
 
30
31
  end
31
32
 
@@ -1,3 +1,3 @@
1
1
  module Simplec
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/simplec.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "simplec/engine"
2
+ require "simplec/embedded_image_actions"
2
3
 
3
4
  module Simplec
4
5
  # TODO configuration options
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Smith
@@ -115,6 +115,7 @@ files:
115
115
  - app/assets/stylesheets/simplec/summernote.scss
116
116
  - app/constraints/simplec/subdomains.rb
117
117
  - app/controllers/simplec/application_controller.rb
118
+ - app/controllers/simplec/embedded_images_controller.rb
118
119
  - app/controllers/simplec/pages_controller.rb
119
120
  - app/helpers/simplec/application_helper.rb
120
121
  - app/jobs/simplec/application_job.rb