blocky 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08b7e1668b91af7bf97863d2b7a497c3ec6aed93
4
- data.tar.gz: 6dbe4418ce56430a2290e9099b7e67a49affc6b9
3
+ metadata.gz: 41a6e1031128ac08f54c5c611c93c83b1c6dd8ce
4
+ data.tar.gz: 4c74e846ebbf5690f26abbbd9f568ad4a97717ea
5
5
  SHA512:
6
- metadata.gz: 307f7f64c3c3a981ffbc880ad6f963960b0074150d017af089bb9d68053852045e8d5da638e82b232685e9d7d5adb8c470dd54e4ccb74ab798bc80ded91ec2df
7
- data.tar.gz: b3eab1aa6791b4e7d478e257157fb3c519f60aa0549fa3dc1b7e36f709fe1d0d4efe484f33a1843cffd29162a2ab67a16a621f9f46c44deaff5e81b6393af89d
6
+ metadata.gz: 896ad606a905626b271650a0dbb7d3debc24912b23a16d9928733351effe42510c4aea37d4e1ab8180980407602e957c75358b12058c77a8d20ad9bd28b751ad
7
+ data.tar.gz: d8d37f05b441730738dba648bbed842ac8071f02495a6efa5a3c5a5f7d0458bf7e6df481994899d9b808b9d7d5a1558ae1b4adb2fbbc2b62b805ce4010fb885c
@@ -1,8 +1,9 @@
1
1
  module Blocky
2
2
  class ContentBlocksController < Blocky::ApplicationController
3
3
  before_action :authorize_user
4
- before_action :set_content_block, only: [:edit, :update]
4
+ before_action :set_content_block, only: [:show, :edit, :update]
5
5
  layout "blocky/application"
6
+ respond_to :html, :json
6
7
 
7
8
  def edit
8
9
  end
@@ -10,25 +11,40 @@ module Blocky
10
11
  def index
11
12
  @global_content_blocks = Blocky::ContentBlock.global
12
13
  @content_blocks = Blocky::ContentBlock.per_page
14
+
15
+ respond_with @content_blocks
13
16
  end
14
17
 
15
18
  def show
16
- redirect_to action: :edit
19
+ respond_to do |format|
20
+ format.html { redirect_to(action: :edit) }
21
+ format.json
22
+ end
17
23
  end
18
24
 
19
25
  def update
20
26
  if @content_block.update(content_block_params)
21
- redirect_to content_blocks_url, notice: "Content block :#{@content_block.name} was updated successfully."
27
+ respond_to do |format|
28
+ format.html {
29
+ redirect_to(content_blocks_url, notice: "Content block :#{@content_block.name} was updated successfully.")
30
+ }
31
+ format.json
32
+ end
22
33
  else
23
- render action: :edit
34
+ respond_to do |format|
35
+ format.html {
36
+ render action: :edit
37
+ }
38
+ format.json
39
+ end
24
40
  end
25
41
  end
26
42
 
27
43
  private
28
44
 
29
- def authorize_user
30
- authorize! :manage, Blocky::ContentBlock
31
- end
45
+ def authorize_user
46
+ authorize! :manage, Blocky::ContentBlock
47
+ end
32
48
 
33
49
  # Use callbacks to share common setup or constraints between actions.
34
50
  def set_content_block
@@ -0,0 +1,43 @@
1
+ module Blocky
2
+ class ImagesController < Blocky::ApplicationController
3
+
4
+ before_action :authorize_user
5
+
6
+ def create
7
+ if s3_bucket
8
+ file = params[:file]
9
+ time_file = create_filename(file)
10
+ s3_object = s3_bucket.objects.create(time_file, file.tempfile, {
11
+ acl: :public_read
12
+ })
13
+ render text: s3_object.public_url.to_s
14
+ else
15
+ throw Exception, "S3 not setup"
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def authorize_user
22
+ authorize! :manage, Blocky::ContentBlock
23
+ end
24
+
25
+ def s3_bucket
26
+ if Blocky.s3_access_key_id && Blocky.s3_secret_access_key && Blocky.s3_bucket
27
+ s3 = AWS::S3.new(
28
+ access_key_id: Blocky.s3_access_key_id,
29
+ secret_access_key: Blocky.s3_secret_access_key
30
+ )
31
+ s3.buckets[Blocky.s3_bucket]
32
+ end
33
+ end
34
+
35
+ def create_filename(file)
36
+ file_ext = File.extname file.original_filename
37
+ file_base = File.basename file.original_filename, file_ext
38
+ time = Time.now.to_i
39
+ file_with_time = "#{file_base}_#{time}#{file_ext}"
40
+ end
41
+
42
+ end
43
+ end
@@ -1,7 +1,7 @@
1
1
  module BlockyHelper
2
2
 
3
3
  def blocky(block_name, options={}, &block)
4
- page_path = options[:global] ? nil : request.fullpath
4
+ page_path = options[:global] ? nil : request.path
5
5
 
6
6
  content_block = Blocky::ContentBlock.where({
7
7
  page_path: page_path,
@@ -19,6 +19,7 @@
19
19
  <% content_for :scripts do %>
20
20
  <script>
21
21
  $(function() {
22
+
22
23
  $('.content-editor').summernote({
23
24
  codemirror: {
24
25
  lineNumbers: true,
@@ -37,8 +38,25 @@
37
38
  ['table', ['table']],
38
39
  ['insert', ['link', 'picture', 'video']],
39
40
  ['code', ['codeview', 'fullscreen']]
40
- ]
41
+ ],
42
+
43
+ onImageUpload: function(files, editor, welEditable) {
44
+ data = new FormData();
45
+ data.append("file", files[0]);
46
+ $.ajax({
47
+ data: data,
48
+ type: "POST",
49
+ url: "../images",
50
+ cache: false,
51
+ contentType: false,
52
+ processData: false,
53
+ success: function(url) {
54
+ editor.insertImage(welEditable, url);
55
+ }
56
+ });
57
+ }
41
58
  });
42
59
  });
43
60
  </script>
44
61
  <% end %>
62
+
@@ -0,0 +1,10 @@
1
+ json.content_blocks @content_blocks do |content_block|
2
+ json.id content_block.id
3
+
4
+ json.content content_block.content
5
+ json.name content_block.name
6
+ json.page_path content_block.page_path
7
+
8
+ json.created_at content_block.created_at
9
+ json.updated_at content_block.updated_at
10
+ end
@@ -0,0 +1,10 @@
1
+ json.content_block do
2
+ json.id @content_block.id
3
+
4
+ json.content @content_block.content
5
+ json.name @content_block.name
6
+ json.page_path @content_block.page_path
7
+
8
+ json.created_at @content_block.created_at
9
+ json.updated_at @content_block.updated_at
10
+ end
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  Blocky::Engine.routes.draw do
2
2
  resources :content_blocks, path: "/"
3
+ resources :images
3
4
  root to: "content_blocks#index"
4
5
  end
data/lib/blocky.rb CHANGED
@@ -1,4 +1,6 @@
1
+ require "aws-sdk"
1
2
  require "cancan"
3
+ require "jbuilder"
2
4
  require "tidy"
3
5
  require "blocky/engine"
4
6
 
@@ -1,3 +1,3 @@
1
1
  module Blocky
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blocky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Pattison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.40'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.40'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: cancan
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jbuilder
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rails
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -332,6 +360,7 @@ files:
332
360
  - app/assets/stylesheets/blocky/shared/typography/lists.scss
333
361
  - app/controllers/blocky/application_controller.rb
334
362
  - app/controllers/blocky/content_blocks_controller.rb
363
+ - app/controllers/blocky/images_controller.rb
335
364
  - app/controllers/concerns/blocky/auth.rb
336
365
  - app/helpers/blocky/application_helper.rb
337
366
  - app/helpers/blocky_helper.rb
@@ -340,6 +369,8 @@ files:
340
369
  - app/views/blocky/content_blocks/_content_block.html.erb
341
370
  - app/views/blocky/content_blocks/edit.html.erb
342
371
  - app/views/blocky/content_blocks/index.html.erb
372
+ - app/views/blocky/content_blocks/index.json.jbuilder
373
+ - app/views/blocky/content_blocks/show.json.jbuilder
343
374
  - app/views/layouts/blocky/_flash_messages.html.erb
344
375
  - app/views/layouts/blocky/application.html.erb
345
376
  - config/jshint.json