nocms-blocks 1.0.0

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.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +8 -0
  3. data/LICENSE +674 -0
  4. data/README.md +233 -0
  5. data/Rakefile +22 -0
  6. data/app/assets/javascripts/no_cms/blocks/application.js +13 -0
  7. data/app/assets/stylesheets/no_cms/blocks/application.css +13 -0
  8. data/app/controllers/no_cms/blocks/application_controller.rb +4 -0
  9. data/app/decorators/models/no_cms/blocks/block_decorator.rb +3 -0
  10. data/app/helpers/no_cms/blocks/application_helper.rb +4 -0
  11. data/app/helpers/no_cms/blocks/blocks_helper.rb +28 -0
  12. data/app/models/no_cms/blocks/block.rb +160 -0
  13. data/app/models/no_cms/blocks/concerns/translation_scopes.rb +16 -0
  14. data/app/views/layouts/no_cms/blocks/application.html.erb +14 -0
  15. data/app/views/no_cms/admin/blocks/blocks/_default.html.erb +9 -0
  16. data/app/views/no_cms/admin/blocks/blocks/_form.html.erb +25 -0
  17. data/app/views/no_cms/admin/blocks/blocks/_index.html.erb +15 -0
  18. data/app/views/no_cms/admin/blocks/blocks/_nested_index.html.erb +17 -0
  19. data/app/views/no_cms/blocks/blocks/_default.html.erb +8 -0
  20. data/config/locales/en.yml +15 -0
  21. data/config/routes.rb +2 -0
  22. data/db/migrate/20140405135410_create_no_cms_blocks_blocks.rb +21 -0
  23. data/db/migrate/20140405150944_add_awesome_nested_set_to_no_cms_blocks.rb +8 -0
  24. data/db/migrate/20140618150651_add_position_to_no_cms_blocks_block.rb +5 -0
  25. data/lib/generators/nocms/blocks_generator.rb +15 -0
  26. data/lib/generators/nocms/templates/config/initializers/nocms/blocks.rb +43 -0
  27. data/lib/no_cms/blocks/configuration.rb +20 -0
  28. data/lib/no_cms/blocks/engine.rb +17 -0
  29. data/lib/no_cms/blocks/version.rb +5 -0
  30. data/lib/nocms-blocks.rb +7 -0
  31. data/lib/tasks/no_cms/blocks.rake +4 -0
  32. data/spec/dummy/README.rdoc +28 -0
  33. data/spec/dummy/Rakefile +6 -0
  34. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  35. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  36. data/spec/dummy/app/controllers/application_controller.rb +8 -0
  37. data/spec/dummy/app/controllers/home_controller.rb +3 -0
  38. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  39. data/spec/dummy/app/models/test_image.rb +5 -0
  40. data/spec/dummy/app/uploaders/logo_uploader.rb +51 -0
  41. data/spec/dummy/app/views/home/show.html.erb +3 -0
  42. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  43. data/spec/dummy/app/views/no_cms/blocks/blocks/_logo_caption.html.erb +5 -0
  44. data/spec/dummy/app/views/no_cms/blocks/blocks/_title_3_columns.html.erb +6 -0
  45. data/spec/dummy/bin/bundle +3 -0
  46. data/spec/dummy/bin/rails +4 -0
  47. data/spec/dummy/bin/rake +4 -0
  48. data/spec/dummy/config.ru +4 -0
  49. data/spec/dummy/config/application.rb +22 -0
  50. data/spec/dummy/config/boot.rb +5 -0
  51. data/spec/dummy/config/database.yml +25 -0
  52. data/spec/dummy/config/environment.rb +5 -0
  53. data/spec/dummy/config/environments/development.rb +29 -0
  54. data/spec/dummy/config/environments/production.rb +80 -0
  55. data/spec/dummy/config/environments/test.rb +38 -0
  56. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  57. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  58. data/spec/dummy/config/initializers/inflections.rb +16 -0
  59. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  60. data/spec/dummy/config/initializers/nocms/blocks.rb +43 -0
  61. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  62. data/spec/dummy/config/initializers/session_store.rb +3 -0
  63. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/spec/dummy/config/locales/en.yml +23 -0
  65. data/spec/dummy/config/routes.rb +5 -0
  66. data/spec/dummy/db/development.sqlite3 +0 -0
  67. data/spec/dummy/db/migrate/20140304094052_create_test_images.rb +9 -0
  68. data/spec/dummy/db/schema.rb +43 -0
  69. data/spec/dummy/db/test.sqlite3 +0 -0
  70. data/spec/dummy/log/development.log +40 -0
  71. data/spec/dummy/log/test.log +33500 -0
  72. data/spec/dummy/public/404.html +58 -0
  73. data/spec/dummy/public/422.html +58 -0
  74. data/spec/dummy/public/500.html +57 -0
  75. data/spec/dummy/public/favicon.ico +0 -0
  76. data/spec/dummy/public/uploads/test_image/logo/1/logo.png +0 -0
  77. data/spec/dummy/public/uploads/test_image/logo/1/logo2.png +0 -0
  78. data/spec/factories/no_cms/blocks/block.rb +8 -0
  79. data/spec/factories/test_image.rb +12 -0
  80. data/spec/fixtures/images/logo.png +0 -0
  81. data/spec/fixtures/images/logo2.png +0 -0
  82. data/spec/models/no_cms/blocks/block_spec.rb +200 -0
  83. data/spec/requests/no_cms/blocks/blocks_spec.rb +95 -0
  84. data/spec/spec_helper.rb +70 -0
  85. data/spec/support/concerns/model_with_has_many_relationship.rb +39 -0
  86. data/spec/support/concerns/model_with_required_attributes.rb +21 -0
  87. metadata +236 -0
@@ -0,0 +1,16 @@
1
+ module NoCms
2
+ module Blocks
3
+ module Concerns
4
+ module TranslationScopes
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ scope :where_with_locale, ->(where_params, locale = ::I18n.locale) {
9
+ with_translations(locale).where(self::Translation.table_name => where_params)
10
+ }
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>NoCmsBlocks</title>
5
+ <%= stylesheet_link_tag "no_cms/blocks/application", media: "all" %>
6
+ <%= javascript_include_tag "no_cms/blocks/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,9 @@
1
+ <div class="row">
2
+ <%= f.label :title %>
3
+ <%= f.text_field :title %>
4
+ </div>
5
+
6
+ <div class="row">
7
+ <%= f.label :body %>
8
+ <%= f.text_area :body %>
9
+ </div>
@@ -0,0 +1,25 @@
1
+ <div class="b-title row">
2
+ <a href="#" class="btn-square ico-collapse-v js-collapse-block" title="Expand /Collapse"></a>
3
+
4
+ <%= f.select :layout, NoCms::Blocks.block_layouts.map{|name, layout| [
5
+ I18n.t("no_cms.blocks.blocks.layouts.#{name}"),
6
+ name,
7
+ 'data-nest-levels' => layout[:nest_levels].nil? ? nil : layout[:nest_levels].to_json
8
+ ]},
9
+ {}, class: 'block_layout_selector' %>
10
+
11
+ <div class="mo">
12
+ <a href="" class="ico-mini-delete"><%= t('.remove') %></a>
13
+ <a href="" class="ico-mini-move-up"><%= t('.move_up') %></a>
14
+ <a href="" class="ico-mini-move-down"><%= t('.move_down') %></a>
15
+ <a href="" class="ico-mini-show-hide"><%= t('.hide') %></a>
16
+ </div>
17
+ </div>
18
+ <div class='layout_fields'>
19
+ <%= render "no_cms/admin/blocks/blocks/#{f.object.template}" , f: f %>
20
+ <%= render 'no_cms/admin/blocks/blocks/nested_index', f: f if f.object.layout_config[:allow_nested_blocks] %>
21
+ </div>
22
+
23
+ <%= f.hidden_field :position, class: 'position' %>
24
+ <%= f.hidden_field :draft, class: 'draft', value: f.object.draft ? '1' : '0' %>
25
+ <%= f.hidden_field :_destroy, class: 'destroy', value: f.object.no_cms_admin_template ? '1' : '0' %>
@@ -0,0 +1,15 @@
1
+ <div class="row has-children content_blocks_placeholder">
2
+ <div class="tool-bar-blocks">
3
+ <a href="#" class="btn-square ico-collapse-v js-collapse-all-children-blocks" title="Collapse all blocks"></a>
4
+ <label><%= t('.title') %></label>
5
+ <%= link_to t('.new_block'), '#', class: 'new_content_block btn _m0' %>
6
+ </div>
7
+
8
+
9
+ <%= f.fields_for :blocks, f.object.blocks.reject(&:parent).sort_by{|b| b.new_record? ? Float::INFINITY : b.position} do |f_block| %>
10
+
11
+ <div class="block row <%= block_form_classes(f_block.object).join(" ")%>" id="<%= block_form_id(f_block.object) %>">
12
+ <%= render 'no_cms/admin/blocks/blocks/form', f: f_block %>
13
+ </div>
14
+ <% end %>
15
+ </div>
@@ -0,0 +1,17 @@
1
+ <div class="row">
2
+ <div class="row has-children content_blocks_placeholder">
3
+ <div class="tool-bar-blocks">
4
+ <a href="#" class="btn-square ico-collapse-v js-collapse-all-children-blocks" title="Collapse all blocks"></a>
5
+ <label><%= t('.title') %></label>
6
+ <%= link_to t('.new_block'), '#', class: 'new_content_block btn _m0' %>
7
+ </div>
8
+
9
+
10
+ <%= f.fields_for :children, f.object.children.sort_by(&:position) do |f_child| %>
11
+
12
+ <div class="block row <%= block_form_classes(f_child.object).join(" ")%>" id="<%= block_form_id(f_child.object) %>">
13
+ <%= render 'no_cms/admin/blocks/blocks/form', f: f_child %>
14
+ </div>
15
+ <% end %>
16
+ </div>
17
+ </div>
@@ -0,0 +1,8 @@
1
+ <div class='block'>
2
+ <% block.fields_info.each do |field_name, field_content| %>
3
+ <div class="<%=field_name %>">
4
+ <h2><%=field_name %></h2>
5
+ <p><%= field_content %></p>
6
+ </div>
7
+ <% end %>
8
+ </div>
@@ -0,0 +1,15 @@
1
+ en:
2
+ no_cms:
3
+ admin:
4
+ blocks:
5
+ blocks:
6
+ index:
7
+ new_block: New block
8
+ title: Blocks
9
+ nested_index:
10
+ new_block: New block
11
+ title: Blocks
12
+ blocks:
13
+ blocks:
14
+ layouts:
15
+ default: 'Default block'
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ NoCms::Blocks::Engine.routes.draw do
2
+ end
@@ -0,0 +1,21 @@
1
+ # This migration comes from no_cms_blocks (originally 20140405135410)
2
+ class CreateNoCmsBlocksBlocks < ActiveRecord::Migration
3
+ def change
4
+ create_table :no_cms_blocks_blocks do |t|
5
+
6
+ t.timestamps
7
+ end
8
+
9
+ NoCms::Blocks::Block.translated_attribute_names = [:locale, :layout, :fields_info, :draft]
10
+
11
+ create_table :no_cms_blocks_block_translations do |t|
12
+ t.belongs_to :no_cms_blocks_block
13
+ t.string :locale
14
+ t.string :layout
15
+ t.text :fields_info, :limit => 4294967295
16
+ t.boolean :draft
17
+ end
18
+
19
+ add_index :no_cms_blocks_block_translations, :no_cms_blocks_block_id, { name: 'no_cms_blocks_blocks_translations_block_id'}
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+ class AddAwesomeNestedSetToNoCmsBlocks < ActiveRecord::Migration
2
+ def change
3
+ add_column :no_cms_blocks_blocks, :parent_id, :integer
4
+ add_column :no_cms_blocks_blocks, :lft, :integer
5
+ add_column :no_cms_blocks_blocks, :rgt, :integer
6
+ add_column :no_cms_blocks_blocks, :depth, :integer
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ class AddPositionToNoCmsBlocksBlock < ActiveRecord::Migration
2
+ def change
3
+ add_column :no_cms_blocks_blocks, :position, :integer
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module NoCms
2
+ class PagesGenerator < Rails::Generators::Base
3
+
4
+ source_root File.expand_path("../templates/", __FILE__)
5
+
6
+ def generate_nocms_pages_initializer
7
+ template "config/initializers/nocms/blocks.rb", File.join(destination_root, "config", "initializers", "nocms", "blocks.rb")
8
+ end
9
+
10
+ def self.namespace
11
+ "nocms:blocks"
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,43 @@
1
+ NoCms::Blocks.configure do |config|
2
+
3
+ # Enable Rails fragment cache for the block templates when you call the render_block helper
4
+ # You can override this cache setting in any block configuration below or sending
5
+ # the cache option true or false when calling the block helpers
6
+ # e.g: render_block block, cache: true
7
+ # config.cache_enabled = false
8
+
9
+ # In this section we configure block layouts. It's just an array of layouts, each consisting on a hash.
10
+ # Each layout has a series of options
11
+ # E.g: config.block_layouts = {
12
+ # 'title-long_text' => {
13
+ # template: 'title-long_text', # This is the template of this block,
14
+ # # used as a partial both in the front
15
+ # # and the admin (if you use the nocms-admin gem)
16
+ # fields: { # This is the list of fields a block with this layout would have
17
+ # title: :string,
18
+ # long_text: :text,
19
+ # image: Image, # You may use another ActiveRecord classes of your own
20
+ # }
21
+ # allow_nested_blocks: true, # A block with this layout may include a list of nested blocks
22
+ # # This setting is actually used by nocms-admin gem to show
23
+ # # nested forms
24
+ # nest_levels: [0] # Some layout may not be nestable, or useful only in certain nesting level
25
+ # # Once again, this setting is used by nocms-admin gem to hide certain
26
+ # # in nested blocks. When blank, it's assumed there's no restriction.
27
+ # cache_enabled: false # When setting cache_enabled you will be **overriding** the global cache_enabled
28
+ # # setting. If you don't set a cache setting then it will use the global cache
29
+ # # setting specified above
30
+ # },
31
+ # 'title-3_columns_text' => {
32
+ # template: 'title-3_columns_text',
33
+ # fields: {
34
+ # title: :string,
35
+ # column_1: :text,
36
+ # column_2: :text,
37
+ # column_3: :text
38
+ # }
39
+ # }
40
+ # }
41
+ # config.block_layouts = {}
42
+
43
+ end
@@ -0,0 +1,20 @@
1
+ module NoCms
2
+ module Blocks
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor :block_layouts
6
+ config_accessor :cache_enabled
7
+
8
+ self.block_layouts = {
9
+ 'default' => {
10
+ template: 'default',
11
+ fields: {
12
+ title: :string,
13
+ body: :text
14
+ }
15
+ }
16
+ }
17
+ self.cache_enabled = false
18
+
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require 'globalize'
2
+ require 'awesome_nested_set'
3
+
4
+ module NoCms
5
+ module Blocks
6
+ class Engine < ::Rails::Engine
7
+ isolate_namespace NoCms::Blocks
8
+
9
+ config.to_prepare do
10
+ Dir.glob(NoCms::Blocks::Engine.root + "app/decorators/**/*_decorator*.rb").each do |c|
11
+ require_dependency(c)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module NoCms
2
+ module Blocks
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "no_cms/blocks/engine"
2
+ require 'no_cms/blocks/configuration'
3
+
4
+ module NoCms
5
+ module Blocks
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :blocks do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,8 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+
6
+ helper NoCms::Blocks::BlocksHelper
7
+
8
+ end
@@ -0,0 +1,3 @@
1
+ class HomeController < ApplicationController
2
+
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,5 @@
1
+ class TestImage < ActiveRecord::Base
2
+ mount_uploader :logo, LogoUploader
3
+
4
+ validates :name, presence: true
5
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ class LogoUploader < CarrierWave::Uploader::Base
4
+
5
+ # Include RMagick or MiniMagick support:
6
+ # include CarrierWave::RMagick
7
+ # include CarrierWave::MiniMagick
8
+
9
+ # Choose what kind of storage to use for this uploader:
10
+ storage :file
11
+ # storage :fog
12
+
13
+ # Override the directory where uploaded files will be stored.
14
+ # This is a sensible default for uploaders that are meant to be mounted:
15
+ def store_dir
16
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
17
+ end
18
+
19
+ # Provide a default URL as a default if there hasn't been a file uploaded:
20
+ # def default_url
21
+ # # For Rails 3.1+ asset pipeline compatibility:
22
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
23
+ #
24
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
25
+ # end
26
+
27
+ # Process files as they are uploaded:
28
+ # process :scale => [200, 300]
29
+ #
30
+ # def scale(width, height)
31
+ # # do something
32
+ # end
33
+
34
+ # Create different versions of your uploaded files:
35
+ # version :thumb do
36
+ # process :resize_to_fit => [50, 50]
37
+ # end
38
+
39
+ # Add a white list of extensions which are allowed to be uploaded.
40
+ # For images you might use something like this:
41
+ # def extension_white_list
42
+ # %w(jpg jpeg gif png)
43
+ # end
44
+
45
+ # Override the filename of the uploaded files:
46
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
47
+ # def filename
48
+ # "something.jpg" if original_filename
49
+ # end
50
+
51
+ end