From e39101837d0dfe2cc8bf0184c3562f6fd013af87 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Thu, 11 Dec 2014 23:45:41 +0100 Subject: [PATCH 01/37] Removing the block model AND the blocks table --- app/models/no_cms/pages/block.rb | 174 ------------------ ...41211224348_destroy_no_cms_pages_blocks.rb | 5 + ...estroy_no_cms_pages_blocks.no_cms_pages.rb | 6 + spec/dummy/db/schema.rb | 13 +- 4 files changed, 12 insertions(+), 186 deletions(-) delete mode 100644 app/models/no_cms/pages/block.rb create mode 100644 db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb create mode 100644 spec/dummy/db/migrate/20141211224504_destroy_no_cms_pages_blocks.no_cms_pages.rb diff --git a/app/models/no_cms/pages/block.rb b/app/models/no_cms/pages/block.rb deleted file mode 100644 index 7e83209..0000000 --- a/app/models/no_cms/pages/block.rb +++ /dev/null @@ -1,174 +0,0 @@ -module NoCms::Pages - class Block < ActiveRecord::Base - - include NoCms::Pages::Concerns::TranslationScopes - - scope :drafts, ->() { where_with_locale(draft: true) } - scope :no_drafts, ->() { where_with_locale(draft: false) } - scope :roots, ->() { where parent_id: nil } - belongs_to :page - - belongs_to :parent, class_name: "NoCms::Pages::Block" - has_many :children, class_name: "NoCms::Pages::Block", foreign_key: 'parent_id', inverse_of: :parent, dependent: :destroy - accepts_nested_attributes_for :children, allow_destroy: true - - attr_reader :cached_objects - - translates :layout, :fields_info, :draft - - class Translation - serialize :fields_info, Hash - end - - after_initialize :set_blank_fields - after_create :set_default_position - before_save :save_related_objects - before_validation :copy_parent_page - - validates :fields_info, presence: { allow_blank: true } - validates :page, :layout, presence: true - - def position - self[:position] || 0 - end - - def layout_config - NoCms::Pages.block_layouts.stringify_keys[layout] - end - - def template - layout_config[:template] if layout_config - end - - def cache_enabled - return NoCms::Pages.cache_enabled unless layout_config - layout_config.has_key?(:cache_enabled) ? layout_config[:cache_enabled] : NoCms::Pages.cache_enabled - end - - def has_field? field - # We have the field if... - !layout_config.nil? && # We have a layout configuration AND - ( - !layout_config[:fields].symbolize_keys[field.to_sym].nil? || # We have this field OR - !layout_config[:fields].symbolize_keys[field.to_s.gsub(/\_id$/, '').to_sym].nil? # we remove the final _id and then we have the field - ) - end - - def field_type field - return nil unless has_field?(field) - layout_config[:fields].symbolize_keys[field.to_sym] - end - - def read_field field - return nil unless has_field?(field) - - value = fields_info[field.to_sym] || # first, we get the value - @cached_objects[field.to_sym] # or we get it from the cached objects - - # If value is still nil, but the field exists we must get the object from the database - if value.nil? - field_type = field_type(field) - field_id = fields_info["#{field}_id".to_sym] - value = @cached_objects[field.to_sym] = field_type.find(field_id) unless field_id.nil? - end - - # If value is still nil, and the field_type is an ActiveRecord class, then we - if value.nil? && field_type.is_a?(Class) - value = @cached_objects[field.to_sym] = field_type.new - end - value - end - - def write_field field, value - return nil unless has_field?(field) - field_type = field_type field - # If field type is a model then we update the cached object - if field_type.is_a?(Class) && field_type < ActiveRecord::Base - # First, we initialize the object if we don't read the object (it loads it into the cached objects) - @cached_objects[field.to_sym] = field_type.new if read_field(field).nil? - # Then, assign attributes - @cached_objects[field.to_sym].assign_attributes value - else # If it's a model then a new object or update the previous one - self.fields_info = fields_info.merge field.to_sym => value # when updating through an object (i.e. the page updates through nested attributes) fields_info[field.to_sym] = value doesn't work. Kudos to Rubo for this fix - end - end - - # In this missing method we check wether we're asking for one field - # in which case we will read or write ir - def method_missing(m, *args, &block) - # We get the name of the field stripping out the '=' for writers - field = m.to_s - write_accessor = field.ends_with? '=' - field.gsub!(/\=$/, '') - - # If this field actually exists, then we write it or read it. - if has_field?(field) - write_accessor ? - write_field(field, args.first) : - read_field(field.to_sym) - else - super - end - end - - # When we are assigning attributes (this method is called in new, create...) - # we must split those fields from our current layout and those who are not - # (they must be attributes). - # Attributes are processed the usual way and fields are written later - def assign_attributes new_attributes - fields = [] - - set_blank_fields - - # We get the layout - new_layout = new_attributes[:layout] || new_attributes['layout'] - self.layout = new_layout unless new_layout.nil? - - Rails.logger.info "Searching #{new_attributes.keys.inspect} fields in #{self.layout} layout" - - # And now separate fields and attributes - fields = new_attributes.select{|k, _| has_field? k }.symbolize_keys - new_attributes.reject!{|k, _| has_field? k } - - super(new_attributes) - - Rails.logger.info "Writing #{fields.inspect} to #{self.layout} block" - - fields.each do |field_name, value| - self.write_field field_name, value - end - end - - def reload - @cached_objects = {} - super - end - - def copy_parent_page - self.page = parent.page unless parent.nil? - end - - private - - def set_blank_fields - self.fields_info ||= {} - @cached_objects ||= {} - end - - def set_default_position - self.update_attribute :position, ((page.blocks.pluck(:position).compact.max || 0) + 1) if self[:position].blank? - end - - def save_related_objects - # Now we save each activerecord related object - cached_objects.each do |field, object| - # Notice that we don't care if the object is actually saved - # We don't care because there may be some cases where no real information is sent to an object but something is sent (i.e. the locale in a new Globalize translation) and then the object is created empty - # When this happens if we save! the object an error is thrown and we can't leave the object blank - if object.is_a?(ActiveRecord::Base) && object.save - fields_info["#{field}_id".to_sym] = object.id - end - end - end - end -end diff --git a/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb b/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb new file mode 100644 index 0000000..1ee0bb4 --- /dev/null +++ b/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb @@ -0,0 +1,5 @@ +class DestroyNoCmsPagesBlocks < ActiveRecord::Migration + def change + drop_table :no_cms_pages_blocks + end +end diff --git a/spec/dummy/db/migrate/20141211224504_destroy_no_cms_pages_blocks.no_cms_pages.rb b/spec/dummy/db/migrate/20141211224504_destroy_no_cms_pages_blocks.no_cms_pages.rb new file mode 100644 index 0000000..0a34a88 --- /dev/null +++ b/spec/dummy/db/migrate/20141211224504_destroy_no_cms_pages_blocks.no_cms_pages.rb @@ -0,0 +1,6 @@ +# This migration comes from no_cms_pages (originally 20141211224348) +class DestroyNoCmsPagesBlocks < ActiveRecord::Migration + def change + drop_table :no_cms_pages_blocks + end +end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 55c5ff8..da888e2 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140806074938) do +ActiveRecord::Schema.define(version: 20141211224504) do create_table "no_cms_pages_block_translations", force: true do |t| t.integer "no_cms_pages_block_id" @@ -23,17 +23,6 @@ add_index "no_cms_pages_block_translations", ["no_cms_pages_block_id"], name: "index_no_cms_pages_block_translations_on_no_cms_pages_block_id" - create_table "no_cms_pages_blocks", force: true do |t| - t.integer "page_id" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "position" - t.integer "parent_id" - end - - add_index "no_cms_pages_blocks", ["page_id"], name: "index_no_cms_pages_blocks_on_page_id" - add_index "no_cms_pages_blocks", ["parent_id"], name: "index_no_cms_pages_blocks_on_parent_id" - create_table "no_cms_pages_page_translations", force: true do |t| t.integer "no_cms_pages_page_id" t.string "locale" From 6bb6cd77573921bc02b663786f3d745884fdcd22 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Thu, 11 Dec 2014 23:49:56 +0100 Subject: [PATCH 02/37] Included nocms-blocks gem --- Gemfile | 2 ++ Gemfile.lock | 19 +++++++++++++++---- lib/nocms/pages/engine.rb | 1 + pages.gemspec | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index fbefdb3..62f4943 100644 --- a/Gemfile +++ b/Gemfile @@ -24,3 +24,5 @@ group :test do gem 'capybara' gem 'database_cleaner' end + +gem "nocms-blocks", git: 'git@github.com:simplelogica/nocms-blocks.git', branch: 'master' diff --git a/Gemfile.lock b/Gemfile.lock index 074bad3..e8d084a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,19 @@ +GIT + remote: git@github.com:simplelogica/nocms-blocks.git + revision: 682039b9f973976e0d9656c524e2f8655235ff4c + branch: master + specs: + nocms-blocks (0.0.1) + awesome_nested_set (>= 3.0.0.rc.6) + rails (~> 4.0, >= 4.0.3) + PATH remote: . specs: nocms-pages (0.0.1) awesome_nested_set (>= 3.0.0.rc.6) globalize (~> 4.0, >= 4.0.0) + nocms-blocks rails (~> 4.0, >= 4.0.3) GEM @@ -34,7 +44,7 @@ GEM thread_safe (~> 0.1) tzinfo (~> 0.3.37) arel (4.0.2) - awesome_nested_set (3.0.0) + awesome_nested_set (3.0.1) activerecord (>= 4.0.0, < 5) builder (3.1.4) capybara (2.2.1) @@ -55,7 +65,7 @@ GEM activesupport (>= 3.0.0) faker (1.2.0) i18n (~> 0.5) - globalize (4.0.0) + globalize (4.0.1) activemodel (>= 4.0.0, < 5) activerecord (>= 4.0.0, < 5) hike (1.2.3) @@ -70,7 +80,7 @@ GEM multi_json (1.10.1) nokogiri (1.6.1) mini_portile (~> 0.5.0) - polyglot (0.3.4) + polyglot (0.3.5) rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) @@ -108,7 +118,7 @@ GEM rspec-mocks (= 3.0.0.beta2) rspec-support (= 3.0.0.beta2) rspec-support (3.0.0.beta2) - sprockets (2.11.0) + sprockets (2.12.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) @@ -137,6 +147,7 @@ DEPENDENCIES database_cleaner factory_girl faker + nocms-blocks! nocms-pages! rspec-rails (~> 3.0.0.beta) sqlite3 diff --git a/lib/nocms/pages/engine.rb b/lib/nocms/pages/engine.rb index 28daa9d..727e3b7 100644 --- a/lib/nocms/pages/engine.rb +++ b/lib/nocms/pages/engine.rb @@ -1,4 +1,5 @@ require 'globalize' +require 'nocms-blocks' require 'awesome_nested_set' module NoCms diff --git a/pages.gemspec b/pages.gemspec index 8dffaec..d47fdeb 100644 --- a/pages.gemspec +++ b/pages.gemspec @@ -18,6 +18,7 @@ Gem::Specification.new do |s| s.add_dependency "rails", '~> 4.0', '>= 4.0.3' s.add_dependency "globalize", '~> 4.0', '>= 4.0.0' s.add_dependency "awesome_nested_set", '>= 3.0.0.rc.6' + s.add_dependency "nocms-blocks" s.add_development_dependency "sqlite3" end From f4f8d3eca153336e9da8dc572eb2cb51169baa79 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Thu, 11 Dec 2014 23:50:34 +0100 Subject: [PATCH 03/37] Initializer and migrations from nocms-blocks gem --- .../dummy/config/initializers/nocms/blocks.rb | 43 +++++++++++++++++++ ...eate_no_cms_blocks_blocks.no_cms_blocks.rb | 22 ++++++++++ ...sted_set_to_no_cms_blocks.no_cms_blocks.rb | 9 ++++ ...on_to_no_cms_blocks_block.no_cms_blocks.rb | 6 +++ spec/dummy/db/schema.rb | 22 +++++++++- 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 spec/dummy/config/initializers/nocms/blocks.rb create mode 100644 spec/dummy/db/migrate/20141211224838_create_no_cms_blocks_blocks.no_cms_blocks.rb create mode 100644 spec/dummy/db/migrate/20141211224839_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb create mode 100644 spec/dummy/db/migrate/20141211224840_add_position_to_no_cms_blocks_block.no_cms_blocks.rb diff --git a/spec/dummy/config/initializers/nocms/blocks.rb b/spec/dummy/config/initializers/nocms/blocks.rb new file mode 100644 index 0000000..479efac --- /dev/null +++ b/spec/dummy/config/initializers/nocms/blocks.rb @@ -0,0 +1,43 @@ +NoCms::Blocks.configure do |config| + + # Enable Rails fragment cache for the block templates when you call the render_block helper + # You can override this cache setting in any block configuration below or sending + # the cache option true or false when calling the block helpers + # e.g: render_block block, cache: true + # config.cache_enabled = false + + # In this section we configure block layouts. It's just an array of layouts, each consisting on a hash. + # Each layout has a series of options + # E.g: config.block_layouts = { + # 'title-long_text' => { + # template: 'title-long_text', # This is the template of this block, + # # used as a partial both in the front + # # and the admin (if you use the nocms-admin gem) + # fields: { # This is the list of fields a block with this layout would have + # title: :string, + # long_text: :text, + # image: Image, # You may use another ActiveRecord classes of your own + # } + # allow_nested_blocks: true, # A block with this layout may include a list of nested blocks + # # This setting is actually used by nocms-admin gem to show + # # nested forms + # nest_levels: [0] # Some layout may not be nestable, or useful only in certain nesting level + # # Once again, this setting is used by nocms-admin gem to hide certain + # # in nested blocks. When blank, it's assumed there's no restriction. + # cache_enabled: false # When setting cache_enabled you will be **overriding** the global cache_enabled + # # setting. If you don't set a cache setting then it will use the global cache + # # setting specified above + # }, + # 'title-3_columns_text' => { + # template: 'title-3_columns_text', + # fields: { + # title: :string, + # column_1: :text, + # column_2: :text, + # column_3: :text + # } + # } + # } + # config.block_layouts = {} + +end diff --git a/spec/dummy/db/migrate/20141211224838_create_no_cms_blocks_blocks.no_cms_blocks.rb b/spec/dummy/db/migrate/20141211224838_create_no_cms_blocks_blocks.no_cms_blocks.rb new file mode 100644 index 0000000..3183b1d --- /dev/null +++ b/spec/dummy/db/migrate/20141211224838_create_no_cms_blocks_blocks.no_cms_blocks.rb @@ -0,0 +1,22 @@ +# This migration comes from no_cms_blocks (originally 20140405135410) +# This migration comes from no_cms_blocks (originally 20140405135410) +class CreateNoCmsBlocksBlocks < ActiveRecord::Migration + def change + create_table :no_cms_blocks_blocks do |t| + + t.timestamps + end + + NoCms::Blocks::Block.translated_attribute_names = [:locale, :layout, :fields_info, :draft] + + create_table :no_cms_blocks_block_translations do |t| + t.belongs_to :no_cms_blocks_block + t.string :locale + t.string :layout + t.text :fields_info, :limit => 4294967295 + t.boolean :draft + end + + add_index :no_cms_blocks_block_translations, :no_cms_blocks_block_id, { name: 'no_cms_blocks_blocks_translations_block_id'} + end +end diff --git a/spec/dummy/db/migrate/20141211224839_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb b/spec/dummy/db/migrate/20141211224839_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb new file mode 100644 index 0000000..84d1e91 --- /dev/null +++ b/spec/dummy/db/migrate/20141211224839_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb @@ -0,0 +1,9 @@ +# This migration comes from no_cms_blocks (originally 20140405150944) +class AddAwesomeNestedSetToNoCmsBlocks < ActiveRecord::Migration + def change + add_column :no_cms_blocks_blocks, :parent_id, :integer + add_column :no_cms_blocks_blocks, :lft, :integer + add_column :no_cms_blocks_blocks, :rgt, :integer + add_column :no_cms_blocks_blocks, :depth, :integer + end +end diff --git a/spec/dummy/db/migrate/20141211224840_add_position_to_no_cms_blocks_block.no_cms_blocks.rb b/spec/dummy/db/migrate/20141211224840_add_position_to_no_cms_blocks_block.no_cms_blocks.rb new file mode 100644 index 0000000..3c150a8 --- /dev/null +++ b/spec/dummy/db/migrate/20141211224840_add_position_to_no_cms_blocks_block.no_cms_blocks.rb @@ -0,0 +1,6 @@ +# This migration comes from no_cms_blocks (originally 20140618150651) +class AddPositionToNoCmsBlocksBlock < ActiveRecord::Migration + def change + add_column :no_cms_blocks_blocks, :position, :integer + end +end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index da888e2..125714d 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -11,7 +11,27 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141211224504) do +ActiveRecord::Schema.define(version: 20141211224840) do + + create_table "no_cms_blocks_block_translations", force: true do |t| + t.integer "no_cms_blocks_block_id" + t.string "locale" + t.string "layout" + t.text "fields_info", limit: 4294967295 + t.boolean "draft" + end + + add_index "no_cms_blocks_block_translations", ["no_cms_blocks_block_id"], name: "no_cms_blocks_blocks_translations_block_id" + + create_table "no_cms_blocks_blocks", force: true do |t| + t.datetime "created_at" + t.datetime "updated_at" + t.integer "parent_id" + t.integer "lft" + t.integer "rgt" + t.integer "depth" + t.integer "position" + end create_table "no_cms_pages_block_translations", force: true do |t| t.integer "no_cms_pages_block_id" From 83767bd4b3ac1883c3264bdf9c7da91b77e9af3f Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Fri, 12 Dec 2014 00:16:25 +0100 Subject: [PATCH 04/37] Replacing the old relation with blocks with the relation with nocms_blocks model --- app/models/no_cms/pages/page.rb | 2 +- ...243_create_no_cms_blocks_no_cms_pages_relation.rb | 11 +++++++++++ ..._cms_blocks_no_cms_pages_relation.no_cms_pages.rb | 12 ++++++++++++ spec/dummy/db/schema.rb | 9 ++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20141211225243_create_no_cms_blocks_no_cms_pages_relation.rb create mode 100644 spec/dummy/db/migrate/20141211225408_create_no_cms_blocks_no_cms_pages_relation.no_cms_pages.rb diff --git a/app/models/no_cms/pages/page.rb b/app/models/no_cms/pages/page.rb index 779c56a..dbbeb91 100644 --- a/app/models/no_cms/pages/page.rb +++ b/app/models/no_cms/pages/page.rb @@ -12,7 +12,7 @@ def self.home acts_as_nested_set - has_many :blocks, inverse_of: :page, class_name: 'NoCms::Pages::Block' + has_and_belongs_to_many :blocks, class_name: "NoCms::Blocks::Block" accepts_nested_attributes_for :blocks, allow_destroy: true translates :title, :body, :slug, :path, :draft, :css_class, :css_id, :cache_enabled diff --git a/db/migrate/20141211225243_create_no_cms_blocks_no_cms_pages_relation.rb b/db/migrate/20141211225243_create_no_cms_blocks_no_cms_pages_relation.rb new file mode 100644 index 0000000..a2e6936 --- /dev/null +++ b/db/migrate/20141211225243_create_no_cms_blocks_no_cms_pages_relation.rb @@ -0,0 +1,11 @@ +class CreateNoCmsBlocksNoCmsPagesRelation < ActiveRecord::Migration + def change + create_table :no_cms_blocks_blocks_pages_pages, id: false do |t| + + t.belongs_to :page + t.belongs_to :block + + t.timestamps + end + end +end diff --git a/spec/dummy/db/migrate/20141211225408_create_no_cms_blocks_no_cms_pages_relation.no_cms_pages.rb b/spec/dummy/db/migrate/20141211225408_create_no_cms_blocks_no_cms_pages_relation.no_cms_pages.rb new file mode 100644 index 0000000..69d98ef --- /dev/null +++ b/spec/dummy/db/migrate/20141211225408_create_no_cms_blocks_no_cms_pages_relation.no_cms_pages.rb @@ -0,0 +1,12 @@ +# This migration comes from no_cms_pages (originally 20141211225243) +class CreateNoCmsBlocksNoCmsPagesRelation < ActiveRecord::Migration + def change + create_table :no_cms_blocks_blocks_pages_pages, id: false do |t| + + t.belongs_to :page + t.belongs_to :block + + t.timestamps + end + end +end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 125714d..8230783 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141211224840) do +ActiveRecord::Schema.define(version: 20141211225408) do create_table "no_cms_blocks_block_translations", force: true do |t| t.integer "no_cms_blocks_block_id" @@ -33,6 +33,13 @@ t.integer "position" end + create_table "no_cms_blocks_blocks_pages_pages", id: false, force: true do |t| + t.integer "page_id" + t.integer "block_id" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "no_cms_pages_block_translations", force: true do |t| t.integer "no_cms_pages_block_id" t.string "locale" From 9dd0598cf4f6e6e970f434992101f9779da5cec8 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Fri, 12 Dec 2014 00:17:01 +0100 Subject: [PATCH 05/37] Adapted model specs to this new relationship --- spec/factories/nocms/pages/block.rb | 8 - spec/models/nocms/pages/block_spec.rb | 214 ++--------------------- spec/models/nocms/pages/page_spec.rb | 1 - spec/requests/no_cms/pages/pages_spec.rb | 10 +- spec/spec_helper.rb | 2 + 5 files changed, 17 insertions(+), 218 deletions(-) delete mode 100644 spec/factories/nocms/pages/block.rb diff --git a/spec/factories/nocms/pages/block.rb b/spec/factories/nocms/pages/block.rb deleted file mode 100644 index 3d972d0..0000000 --- a/spec/factories/nocms/pages/block.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl - -FactoryGirl.define do - factory :nocms_block, class: NoCms::Pages::Block do - layout { 'default' } - page { FactoryGirl.create :nocms_page } - end -end diff --git a/spec/models/nocms/pages/block_spec.rb b/spec/models/nocms/pages/block_spec.rb index b51bdae..d91c601 100644 --- a/spec/models/nocms/pages/block_spec.rb +++ b/spec/models/nocms/pages/block_spec.rb @@ -1,15 +1,13 @@ require 'spec_helper' -describe NoCms::Pages::Block do - it_behaves_like "model with required attributes", :nocms_block, [:layout, :page] - it_behaves_like "model with has many relationship", :nocms_block, :nocms_block, :children, :parent +describe NoCms::Blocks::Block do context "when blocks have layouts" do context "with simple fields" do before do - NoCms::Pages.configure do |config| + NoCms::Blocks.configure do |config| config.block_layouts = { 'title-long_text' => { template: 'title-long_text', @@ -22,70 +20,25 @@ end end - let(:block_with_layout) { NoCms::Pages::Block.create attributes_for(:nocms_block).merge(layout: 'title-long_text', title: block_title) } + let(:block_with_layout) { NoCms::Blocks::Block.create attributes_for(:block).merge(layout: 'title-long_text', title: block_title) } let(:block_title) { Faker::Lorem.sentence } + let(:page) { create :nocms_page } subject { block_with_layout } - it("should respond to layout fields") do - expect{subject.title}.to_not raise_error - expect{subject.body}.to_not raise_error - end - - it("should not respond to fields from other layouts") do - expect{subject.no_title}.to raise_error - end - - it("should save info in layout fields") do - expect(subject.title).to eq block_title - end - - it("should save nil fields") do - expect(subject.body).to be_blank - end - - context "when updating various fields" do - - let(:new_block_title) { "new #{Faker::Lorem.sentence}" } - let(:block_body) { Faker::Lorem.paragraph } - - before do - subject.update_attributes title: new_block_title, body: block_body - end - - it("should save info in layout fields") do - expect(subject.title).to eq new_block_title - expect(subject.body).to eq block_body - end - - end - - context "when updating just one field" do - - let(:new_block_title) { "new #{Faker::Lorem.sentence}" } - - before do - subject.update_attribute :title, new_block_title - end - - it("should save info in layout field") do - expect(subject.title).to eq new_block_title - end - - end - context "when updating one field of the block through the page" do let(:new_block_title) { "new #{Faker::Lorem.sentence}" } let(:new_page_title) { "new page #{Faker::Lorem.sentence}" } before do - subject.page.update_attributes! title: new_page_title, blocks_attributes: { "0" => { title: new_block_title, id: subject.id } } + page.blocks << subject + page.update_attributes! title: new_page_title, blocks_attributes: { "0" => { title: new_block_title, id: subject.id } } end it("should save info in layout field") do subject.reload - expect(subject.page.title).to eq new_page_title + expect(page.title).to eq new_page_title expect(subject.title).to eq new_block_title end @@ -99,12 +52,13 @@ let(:new_page_title) { "new page #{Faker::Lorem.sentence}" } before do - subject.page.update_attributes! title: new_page_title, blocks_attributes: { "0" => { title: new_block_title, body: new_block_body, id: subject.id } } + page.blocks << subject + page.update_attributes! title: new_page_title, blocks_attributes: { "0" => { title: new_block_title, body: new_block_body, id: subject.id } } end it("should save info in layout field") do subject.reload - expect(subject.page.title).to eq new_page_title + expect(page.title).to eq new_page_title expect(subject.title).to eq new_block_title expect(subject.body).to eq new_block_body end @@ -113,154 +67,6 @@ end - context "with related models" do - - before do - NoCms::Pages.configure do |config| - config.block_layouts = { - 'logo-caption' => { - template: 'logo_caption', - fields: { - caption: :string, - logo: TestImage - } - } - } - end - end - - let(:image_attributes) { attributes_for(:test_image) } - - let(:block_with_layout) { NoCms::Pages::Block.create attributes_for(:nocms_block).merge( - layout: 'logo-caption', - caption: Faker::Lorem.sentence, - logo: image_attributes - ) - } - before { subject } - subject { block_with_layout } - - it("should respond to layout fields") do - expect{subject.caption}.to_not raise_error - expect{subject.logo}.to_not raise_error - end - - it("should return objects") do - expect(subject.logo).to be_a(TestImage) - end - - it("should return objects with the right value") do - expect(subject.logo.name).to eq image_attributes[:name] - end - - it("should save related objects") do - expect(TestImage.first).to_not be_nil - end - - context "when related objects are modified outside" do - - let(:logo) { TestImage.first } - let(:new_testing_name) { "new testing name" } - - before do - subject - logo.update_attribute :name, new_testing_name - end - - it("should get those modifications") do - expect(subject.reload.logo.name).to eq new_testing_name - end - - it("should not overwrite those modifications") do - subject.save! - expect(logo.reload.name).to eq new_testing_name - end - - end - - context "when we update the related object" do - - let(:logo) { TestImage.first } - let(:new_testing_name) { "new testing name" } - let(:new_image_attributes) { attributes_for(:test_image,:second_image) } - - before do - subject.update_attributes logo: { name: new_testing_name, logo: new_image_attributes[:logo] } - end - - it("should be modified in database") do - expect(logo.name).to eq new_testing_name - end - - it("should modify uploaded files") do - expect(logo[:logo]).to eq File.basename(new_image_attributes[:logo].path) - end - - end - - context "when the related object is not valid" do - - let(:logo) { TestImage.first } - let(:new_testing_caption) { "new testing caption" } - - before do - subject.update_attributes caption: new_testing_caption, logo: { name: nil } - end - - it("should modify the block attribute") do - expect(subject.reload.caption).to eq new_testing_caption - end - - it("should not modify the invalid objects") do - expect(subject.logo.name).to_not eq logo.name - end - - end - - - end - - end - - context "when asigning blocks to pages" do - - let(:page) { create :nocms_page } - let(:block_1) { create :nocms_block, page: page } - let(:block_2) { create :nocms_block, page: page } - - it "blocks positions should be correctly assigned" do - expect(block_1.position).to eq 1 - expect(block_2.position).to eq 2 - end - - context "when having assigned a different position to a block" do - - let(:last_block) { create :nocms_block, page: page } - - before do - block_1 - block_2.update_attribute :position, 10 - end - - it "new block should be the last one" do - expect(last_block.position).to eq 11 - end - - end - - end - - context "when blocks are marked as draft" do - - let(:no_draft_blocks) { create_list :nocms_block, 2, draft: false } - let(:draft_blocks) { create_list :nocms_block, 2, draft: true } - - before { draft_blocks && no_draft_blocks } - - it("should distinguish between drafts and no drafts") do - expect(NoCms::Pages::Block.drafts).to match_array draft_blocks - expect(NoCms::Pages::Block.no_drafts).to match_array no_draft_blocks - end end end diff --git a/spec/models/nocms/pages/page_spec.rb b/spec/models/nocms/pages/page_spec.rb index b210c27..9bd90ac 100644 --- a/spec/models/nocms/pages/page_spec.rb +++ b/spec/models/nocms/pages/page_spec.rb @@ -2,7 +2,6 @@ describe NoCms::Pages::Page do it_behaves_like "model with required attributes", :nocms_page, [:title, :body] - it_behaves_like "model with has many relationship", :nocms_page, :nocms_block, :blocks, :page it_behaves_like "model with has many relationship", :nocms_page, :nocms_page, :children, :parent context "when creating" do diff --git a/spec/requests/no_cms/pages/pages_spec.rb b/spec/requests/no_cms/pages/pages_spec.rb index 7c6e744..e36e207 100644 --- a/spec/requests/no_cms/pages/pages_spec.rb +++ b/spec/requests/no_cms/pages/pages_spec.rb @@ -6,12 +6,12 @@ let(:cms_page) { create :nocms_page } let(:image_attributes) { attributes_for(:test_image) } - let(:block_default_layout) { create :nocms_block, layout: 'default', page: cms_page, title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph } - let(:block_3_columns_layout) { create :nocms_block, layout: 'title-3_columns', page: cms_page, title: Faker::Lorem.sentence, column_1: Faker::Lorem.paragraph, column_2: Faker::Lorem.paragraph, column_3: Faker::Lorem.paragraph } - let(:block_logo) { create :nocms_block, layout: 'logo-caption', page: cms_page, caption: Faker::Lorem.sentence, logo: image_attributes } - let(:block_draft) { create :nocms_block, layout: 'default', page: cms_page, title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph, draft: true } + let(:block_default_layout) { create :nocms_block, layout: 'default', title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph } + let(:block_3_columns_layout) { create :nocms_block, layout: 'title-3_columns', title: Faker::Lorem.sentence, column_1: Faker::Lorem.paragraph, column_2: Faker::Lorem.paragraph, column_3: Faker::Lorem.paragraph } + let(:block_logo) { create :nocms_block, layout: 'logo-caption', caption: Faker::Lorem.sentence, logo: image_attributes } + let(:block_draft) { create :nocms_block, layout: 'default', title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph, draft: true } - let(:page_blocks) { [block_default_layout , block_3_columns_layout, block_logo, block_draft] } + let(:page_blocks) { cms_page.blocks = [block_default_layout , block_3_columns_layout, block_logo, block_draft] } context "if page exists" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3b67a4c..9c906df 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,6 +8,8 @@ # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("../support/**/*.rb")].each { |f| require f } +FactoryGirl.definition_file_paths << "#{Gem::Specification.find_by_name("nocms-blocks").gem_dir}/spec/factories/no_cms/blocks/" + # Checks for pending migrations before tests are run. # If you are not using ActiveRecord, you can remove this line. From fe36a1915fa58d8c6ad86aee5b3dcd19f27035bf Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Fri, 12 Dec 2014 00:40:02 +0100 Subject: [PATCH 06/37] The render_block from this gem becomes a render_page_blocks which decorates the render_block from nocms-blocks to enable cache on a page --- .../no_cms/pages/application_controller.rb | 1 + app/helpers/no_cms/pages/pages_helper.rb | 19 +++---------------- app/views/no_cms/pages/pages/show.html.erb | 2 +- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/app/controllers/no_cms/pages/application_controller.rb b/app/controllers/no_cms/pages/application_controller.rb index 8e33d9b..febffb5 100644 --- a/app/controllers/no_cms/pages/application_controller.rb +++ b/app/controllers/no_cms/pages/application_controller.rb @@ -1,6 +1,7 @@ module NoCms module Pages class ApplicationController < ::ApplicationController + helper NoCms::Blocks::BlocksHelper end end end diff --git a/app/helpers/no_cms/pages/pages_helper.rb b/app/helpers/no_cms/pages/pages_helper.rb index 2d6de18..78e069b 100644 --- a/app/helpers/no_cms/pages/pages_helper.rb +++ b/app/helpers/no_cms/pages/pages_helper.rb @@ -1,23 +1,10 @@ module NoCms module Pages module PagesHelper - def render_block block, options = {} + def render_page_block page, block, options = {} # If cache is disabled for this block then we disable no matter what the block or the options passed have to say about it. This way, the user in the back has the last word about disabling cache - options[:cache_enabled] = false unless block.page.cache_enabled - # If we don't have any option about cache enabled then we ask the block - options[:cache_enabled] = block.cache_enabled unless options.has_key? :cache_enabled - - block_template = "no_cms/pages/blocks/#{block.template}" - - # And now decide if we use cache or not - if options[:cache_enabled] - Rails.cache.fetch "#{block_template}/#{block.id}/#{block.updated_at.to_i}" do - render block_template, block: block - end - else - render block_template, block: block - end - + options[:cache_enabled] = false unless page.cache_enabled + render_block block, options end end end diff --git a/app/views/no_cms/pages/pages/show.html.erb b/app/views/no_cms/pages/pages/show.html.erb index 221721f..dbedf06 100644 --- a/app/views/no_cms/pages/pages/show.html.erb +++ b/app/views/no_cms/pages/pages/show.html.erb @@ -2,5 +2,5 @@

<%= @page.body %>

<% @blocks.sort_by(&:position).each do |block| %> - <%= render_block block %> + <%= render_page_block @page, block %> <% end %> From 833ad0ba40cba19d91ed6a4875bb198a1da81a39 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Fri, 12 Dec 2014 00:44:25 +0100 Subject: [PATCH 07/37] Moving blocks layouts to the nocms-blocks views folder --- .../views/no_cms/{pages => blocks}/blocks/_logo_caption.html.erb | 0 .../no_cms/{pages => blocks}/blocks/_title_3_columns.html.erb | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename spec/dummy/app/views/no_cms/{pages => blocks}/blocks/_logo_caption.html.erb (100%) rename spec/dummy/app/views/no_cms/{pages => blocks}/blocks/_title_3_columns.html.erb (100%) diff --git a/spec/dummy/app/views/no_cms/pages/blocks/_logo_caption.html.erb b/spec/dummy/app/views/no_cms/blocks/blocks/_logo_caption.html.erb similarity index 100% rename from spec/dummy/app/views/no_cms/pages/blocks/_logo_caption.html.erb rename to spec/dummy/app/views/no_cms/blocks/blocks/_logo_caption.html.erb diff --git a/spec/dummy/app/views/no_cms/pages/blocks/_title_3_columns.html.erb b/spec/dummy/app/views/no_cms/blocks/blocks/_title_3_columns.html.erb similarity index 100% rename from spec/dummy/app/views/no_cms/pages/blocks/_title_3_columns.html.erb rename to spec/dummy/app/views/no_cms/blocks/blocks/_title_3_columns.html.erb From 594a9438e2e4b61957b185d82c94e531d7aa5674 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Fri, 12 Dec 2014 00:45:01 +0100 Subject: [PATCH 08/37] Adapting request specs to the new blocks relationship --- spec/requests/no_cms/pages/pages_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/requests/no_cms/pages/pages_spec.rb b/spec/requests/no_cms/pages/pages_spec.rb index e36e207..1970448 100644 --- a/spec/requests/no_cms/pages/pages_spec.rb +++ b/spec/requests/no_cms/pages/pages_spec.rb @@ -6,17 +6,17 @@ let(:cms_page) { create :nocms_page } let(:image_attributes) { attributes_for(:test_image) } - let(:block_default_layout) { create :nocms_block, layout: 'default', title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph } - let(:block_3_columns_layout) { create :nocms_block, layout: 'title-3_columns', title: Faker::Lorem.sentence, column_1: Faker::Lorem.paragraph, column_2: Faker::Lorem.paragraph, column_3: Faker::Lorem.paragraph } - let(:block_logo) { create :nocms_block, layout: 'logo-caption', caption: Faker::Lorem.sentence, logo: image_attributes } - let(:block_draft) { create :nocms_block, layout: 'default', title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph, draft: true } + let(:block_default_layout) { create :block, layout: 'default', title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph } + let(:block_3_columns_layout) { create :block, layout: 'title-3_columns', title: Faker::Lorem.sentence, column_1: Faker::Lorem.paragraph, column_2: Faker::Lorem.paragraph, column_3: Faker::Lorem.paragraph } + let(:block_logo) { create :block, layout: 'logo-caption', caption: Faker::Lorem.sentence, logo: image_attributes } + let(:block_draft) { create :block, layout: 'default', title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph, draft: true } - let(:page_blocks) { cms_page.blocks = [block_default_layout , block_3_columns_layout, block_logo, block_draft] } + let(:page_blocks) { [block_default_layout , block_3_columns_layout, block_logo, block_draft] } context "if page exists" do before do - NoCms::Pages.configure do |config| + NoCms::Blocks.configure do |config| config.block_layouts = { 'default' => { template: 'default', @@ -45,7 +45,7 @@ end - page_blocks + cms_page.blocks = page_blocks visit cms_page.path end From 930c5701a0ce13ed353d0d5d10ad9aeeb1e51897 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Fri, 12 Dec 2014 00:46:20 +0100 Subject: [PATCH 09/37] Pointing to a new nocms-blocks commit --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index e8d084a..80d275b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git@github.com:simplelogica/nocms-blocks.git - revision: 682039b9f973976e0d9656c524e2f8655235ff4c + revision: efb13dcfcd324a862612e0f024d0ba6ed319a296 branch: master specs: nocms-blocks (0.0.1) From 5a1a66b49d423cd8b8666960d05f5579fba9d5fc Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Fri, 2 Jan 2015 13:10:28 +0100 Subject: [PATCH 10/37] Decorator for NoCmsBlocks for default positions when linked to pages --- app/decorators/no_cms/blocks/block_decorator.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/decorators/no_cms/blocks/block_decorator.rb diff --git a/app/decorators/no_cms/blocks/block_decorator.rb b/app/decorators/no_cms/blocks/block_decorator.rb new file mode 100644 index 0000000..a887c61 --- /dev/null +++ b/app/decorators/no_cms/blocks/block_decorator.rb @@ -0,0 +1,12 @@ +NoCms::Blocks::Block.class_eval do + + after_create :set_default_position + + has_and_belongs_to_many :pages, class_name: 'NoCms::Pages::Page' + + def set_default_position + self.update_attribute :position, ((pages.map{|p| p.blocks.pluck(:position)}).flatten.compact.max || 0) + 1) if self[:position].blank? && self.pages.exists? + end + +end + From 8a4ee9b9903ccde26f8ee5809512eafcf452dc9b Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Mon, 5 Jan 2015 14:40:09 +0100 Subject: [PATCH 11/37] Block decorator fixed (Syntax error) and included on the Block class --- app/decorators/no_cms/blocks/block_decorator.rb | 2 +- lib/nocms/pages/engine.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/decorators/no_cms/blocks/block_decorator.rb b/app/decorators/no_cms/blocks/block_decorator.rb index a887c61..1bd342c 100644 --- a/app/decorators/no_cms/blocks/block_decorator.rb +++ b/app/decorators/no_cms/blocks/block_decorator.rb @@ -5,7 +5,7 @@ has_and_belongs_to_many :pages, class_name: 'NoCms::Pages::Page' def set_default_position - self.update_attribute :position, ((pages.map{|p| p.blocks.pluck(:position)}).flatten.compact.max || 0) + 1) if self[:position].blank? && self.pages.exists? + self.update_attribute :position, (((pages.map{|p| p.blocks.pluck(:position)}).flatten.compact.max || 0) + 1) if self[:position].blank? && self.pages.exists? end end diff --git a/lib/nocms/pages/engine.rb b/lib/nocms/pages/engine.rb index 727e3b7..3ea3053 100644 --- a/lib/nocms/pages/engine.rb +++ b/lib/nocms/pages/engine.rb @@ -6,6 +6,12 @@ module NoCms module Pages class Engine < ::Rails::Engine isolate_namespace NoCms::Pages + + config.to_prepare do + Dir.glob(NoCms::Pages::Engine.root + "app/decorators/**/*_decorator*.rb").each do |c| + require_dependency(c) + end + end end end end From f5b4c6fd9586fe9b7e9351321a6241bd3259febb Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Mon, 5 Jan 2015 15:56:50 +0100 Subject: [PATCH 12/37] Deprecated readonly model for NoCms::Pages::Block --- app/models/no_cms/pages/deprecated/block.rb | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 app/models/no_cms/pages/deprecated/block.rb diff --git a/app/models/no_cms/pages/deprecated/block.rb b/app/models/no_cms/pages/deprecated/block.rb new file mode 100644 index 0000000..fee9d0c --- /dev/null +++ b/app/models/no_cms/pages/deprecated/block.rb @@ -0,0 +1,45 @@ +class NoCms::Pages::Deprecated::Block < ActiveRecord::Base + + self.table_name = "no_cms_pages_blocks" + + + belongs_to :page + belongs_to :parent, class_name: "NoCms::Pages::Deprecated::Block" + has_many :children, class_name: "NoCms::Pages::Deprecated::Block", foreign_key: 'parent_id', inverse_of: :parent, dependent: :destroy + + scope :roots, ->() { where parent_id: nil } + + translates :layout, :fields_info, :draft + + class Translation + self.table_name = "no_cms_pages_block_translations" + serialize :fields_info, Hash + end + + def readonly? + true + end + + def position + self[:position] || 0 + end + + def self.dump + roots.map(&:dump) + end + + def dump + { + page: page, + position: position, + children: children.map(&:dump), + translations: Hash[translations.map{|t| [t.locale, { + layout: t.layout, + draft: t.draft, + fields_info: t.fields_info.to_hash + }]}] + + } + end + +end From 525971719717c9dcca4832835a61ff1137c67f32 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Mon, 5 Jan 2015 15:59:09 +0100 Subject: [PATCH 13/37] Rake task for importing blocks from NoCms::Pages::Deprecated::Block to NoCms::Blocks::Block --- lib/tasks/pages_tasks.rake | 50 +++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/lib/tasks/pages_tasks.rake b/lib/tasks/pages_tasks.rake index 870794e..642afe5 100644 --- a/lib/tasks/pages_tasks.rake +++ b/lib/tasks/pages_tasks.rake @@ -1,4 +1,46 @@ -# desc "Explaining what the task does" -# task :pages do -# # Task goes here -# end +namespace :no_cms do + + namespace :pages do + + desc 'Task for migrating blocks from NoCms::Pages::Block model to NoCms::Blocks::Block' + task :migrate_blocks => :environment do + NoCms::Pages::Page.all.each {|p| p.blocks.clear } + root_blocks = NoCms::Pages::Deprecated::Block.dump + root_blocks.each do |root_block| + import_block root_block + end + end + + def import_block block + return if block[:page].nil? + + # Due to globalize we have to send the default translation via the object attributes + # instead of using the translation_attributes + default_translation = block[:translations][I18n.locale] + other_translations = block[:translations].reject{|locale, _| locale == I18n.locale } + + new_block = block[:page].blocks.build position: block[:position], + translations_attributes: other_translations.map {|locale, translation| + { + locale: locale, + layout: translation[:layout], + draft: translation[:draft], + fields_info: translation[:fields_info].to_hash + } + }, + layout: default_translation[:layout], + draft: default_translation[:draft], + fields_info: default_translation[:fields_info].to_hash + + new_block.translations.each(&:save!) + + new_block.children = block[:children].map{|b| import_block b} + new_block.save! + + block[:page].blocks << new_block + new_block + end + + end + +end From 84cf2663bf15a88eb28a2ee3c596b5664eaaaa93 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Mon, 5 Jan 2015 16:25:59 +0100 Subject: [PATCH 14/37] Relationship between nocms_pages and blocks should be created before we remove the nocms_pages_blocks table --- ... 20141211224243_create_no_cms_blocks_no_cms_pages_relation.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/migrate/{20141211225243_create_no_cms_blocks_no_cms_pages_relation.rb => 20141211224243_create_no_cms_blocks_no_cms_pages_relation.rb} (100%) diff --git a/db/migrate/20141211225243_create_no_cms_blocks_no_cms_pages_relation.rb b/db/migrate/20141211224243_create_no_cms_blocks_no_cms_pages_relation.rb similarity index 100% rename from db/migrate/20141211225243_create_no_cms_blocks_no_cms_pages_relation.rb rename to db/migrate/20141211224243_create_no_cms_blocks_no_cms_pages_relation.rb From d8b84db59a1f0ca84deed598e16221c63ddd52fe Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Mon, 5 Jan 2015 16:45:32 +0100 Subject: [PATCH 15/37] We check that migration can be run and run the rake task for migration --- db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb b/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb index 1ee0bb4..585e5ab 100644 --- a/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb +++ b/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb @@ -1,5 +1,11 @@ class DestroyNoCmsPagesBlocks < ActiveRecord::Migration def change + + if !defined?(NoCms::Blocks::Block) || !NoCms::Blocks::Block.table_exists? + raise Exception.new("Migration destroying no_cms_pages_blocks should only be run after creating NoCms::Blocks::Block table") + end + + Rake::Task["no_cms:pages:migrate_blocks"].invoke drop_table :no_cms_pages_blocks end end From 616e5b6abebc856d2d76c776c121e79e2d42b4fa Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Mon, 5 Jan 2015 17:54:11 +0100 Subject: [PATCH 16/37] Including the NoCms::Pages.cache_enabled control on the helper --- app/helpers/no_cms/pages/pages_helper.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/helpers/no_cms/pages/pages_helper.rb b/app/helpers/no_cms/pages/pages_helper.rb index 78e069b..7fefa3e 100644 --- a/app/helpers/no_cms/pages/pages_helper.rb +++ b/app/helpers/no_cms/pages/pages_helper.rb @@ -2,8 +2,11 @@ module NoCms module Pages module PagesHelper def render_page_block page, block, options = {} - # If cache is disabled for this block then we disable no matter what the block or the options passed have to say about it. This way, the user in the back has the last word about disabling cache - options[:cache_enabled] = false unless page.cache_enabled + # If cache is disabled for all pages or is disabled for this block + # then we disable no matter what the block or the options passed have to say about it. + # This way, the user in the back has the last word about disabling cache and the NoCms::Pages engine + # control the cache over the NoCms::Block engine + options[:cache_enabled] = false if !NoCms::Pages.cache_enabled || !page.cache_enabled render_block block, options end end From e5a2e874843dd3a4fd542337b2a013ea3840c016 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Mon, 5 Jan 2015 17:54:34 +0100 Subject: [PATCH 17/37] Updated README.md with comments about the new blocks --- README.md | 140 ++++++------------------------------------------------ 1 file changed, 15 insertions(+), 125 deletions(-) diff --git a/README.md b/README.md index 75ffc40..1f3b684 100644 --- a/README.md +++ b/README.md @@ -56,133 +56,21 @@ This `template` is set from the template attribute, being `show` the default val ### Blocks -Blocks are the unit of contents the pages are made of. They are thought to be independent and customizable modules that can be created, edited or removed on their own, without dependency of any other module. - -#### Block layouts - -In NoCMS Pages, block layouts define two main things: - -1. What kind of information a block contains and other settings (i.e. cache settings). -2. How this information is displayed within the page. - -Block settings are configured in the file `config/initializers/nocms/pages.rb`. Here we declare all the available layouts for a block. - -The following code - -```ruby -NoCms::Pages.configure do |config| - - config.block_layouts = { - 'default' => { - template: 'default', - fields: { - title: :string, - body: :text - } - }, - 'title-3_columns' => { - template: 'title_3_columns', - fields: { - title: :string, - column_1: :text, - column_2: :text, - column_3: :text - }, - }, - 'logo-caption' => { - template: 'logo_caption', - fields: { - caption: :string, - logo: TestImage - } - } - } - -end -``` - -declares 3 layouts ('default', 'title-3_columns' and 'logo-caption'). Each layout has a template and some declared fields. These fields will be available in the ruby object for that block. As an example, if `@block` is an instance of the NoCms::Pages::Block model which layout attribute is set to 'default' you will be able to do `@block.title` - -```ruby -block = NoCms::Pages::Block.new -block.layout = 'default' - -block.title = 'a title' -block.title # => 'a title' - -block.column_1 = 'a column' # => NoMethodError -block.column_1 # => NoMethodError - - -block.layout = 'title-3_columns' - -block.title # => 'a title' -block.column_1 = 'a column' -block.column_1 # => 'a column' -block.body # => NoMethodError - -block.layout = 'logo_caption' -block.title # => NoMethodError -block.logo = { name: 'testing logo' } # Currently this is the way to assign objects -block.logo.name # => 'testing logo' -block.logo.class # => TestImage -block.logo = TestImage.new name: 'testing logo' # Error! Currently assigning the object is not allowed :( -``` - -#### Block templates - -Blocks are rendered using the `render_block` helper which controls all the logic related with renderinf a block, including fragment cache control. - -In the end a partial is rendered using the block as a local variable to obtain the information. This partial must be found at `no_cms/pages/blocks` views folder and have the name configured in the `template` setting of the block. This way, rendering a 'title-3_columns' would render the partial `/no_cms/pages/blocks/title_3_columns`. - -This partial is a regular Rails partial (nothing special here). AS an example, this could be the content of our `/no_cms/pages/blocks/title_3_columns.html.erb` partial: - -```html -
-

<%= block.title %>

-

<%= block.column_1 %>

-

<%= block.column_2 %>

-

<%= block.column_3 %>

-
-``` - -As you can see, the partial has a block variable containing the block object you are rendering. - -Since this is plain old rails you can do everything you can do with a partial (i.e. having a `/no_cms/pages/blocks/title_3_columns.en.html.erb` for the english version and a `/no_cms/pages/blocks/title_3_columns.es.html.erb` for the spanish one). +In a previous gem version blocks were a model within the NoCms::Pages namespace, but now everything was moved to the [nocms-blocks](https://github.com/simplelogica/nocms-blocks) and in this repo there's only left a rake task for the migration. ### Block Cache -Since blocks are independent units of content within a page, the standard Rails fragment cache seemed to fit well with them. That's why the `render_block` helper decides wether Rails cache should be used for rendering an individual block. - -Cache for the blocks are configured at 3 levels: +Blocks are rendered through the `render_page_block` helper instead of the `render_block` helper from `nocms-blocks`. This helper uses the `render_block` helper but add some extra cache levels: 1. The page may have its `cache_enabled` attribute set to false. If this is the case then the cache will be disabled without any further check. This way, a page can be marked as "not cacheable" (e.g. in an admin interface) and no other setting can overwrite it. -2. The `render_block` helper may be called with a `cache_enabled` option set to true or false. This option will enable/disable the cache. This allow us to render a block without using the cache (maybe on a preview action). +2. The `render_page_block` helper may be called with a `cache_enabled` option set to true or false. This option will enable/disable the cache. This allow us to render a block without using the cache (maybe on a preview action). ```ruby render_block block, cache: false ``` -3. In the blocks configuration we can enable/disable the cache for all the blocks of a kind. We just have to add the cache_enabled setting. - - ```ruby - NoCms::Pages.configure do |config| - - config.block_layouts = { - 'default' => { - template: 'default', - fields: { - title: :string, - body: :text - }, - cache_enabled: false - } - } - end - ``` - -4. In the blocks configuration file we can enable/disable cache for all the blocks that doesn't have a cache_enabled setting. This configuration will be stored at `NoCms::Pages.cache_enabled` +3. In the page configuration file we can enable/disable cache for all the blocks that doesn't have a cache_enabled setting. This configuration will be stored at `NoCms::Pages.cache_enabled` ```ruby NoCms::Pages.configure do |config| @@ -196,23 +84,25 @@ As a summary: ```ruby - b = NoCms::Pages::Block.new layout: 'default', title: 'Foo', description: 'Bar', page: page - b.page.cache_enabled # => true + b = NoCms::Blocks::Block.new layout: 'default', title: 'Foo', description: 'Bar' + page.blocks << b + page.cache_enabled # => true NoCms::Pages.cache_enabled # => true b.cache_enabled # => false, since the block configuration sets it to false - render_block b # => This won't use fragment cache since this block layout have cache disabled + render_page_block b # => This won't use fragment cache since this block layout have cache disabled - b = NoCms::Pages::Block.new layout: 'title-3_columns', title: 'Foo', description: 'Bar', page: page - b.page.cache_enabled # => true + b = NoCms::Blocks::Block.new layout: 'title-3_columns', title: 'Foo', description: 'Bar' + page.blocks << b + page.cache_enabled # => true NoCms::Pages.cache_enabled # => true b.cache_enabled # => true, since this block configuration doesn't override NoCms::Pages.cache_enabled - render_block b # => This will use fragment cache since, by default, it's enabled for all blocks + render_page_block b # => This will use fragment cache since, by default, it's enabled for all blocks - render_block b, cache_enabled: false # => This won't use fragment cache as the option in the helper overrides the block configuration + render_page_block b, cache_enabled: false # => This won't use fragment cache as the option in the helper overrides the block configuration page.cache_enabled = false - render_block b # => This won't use fragment cache sincs it's been disabled for the page and blocks configuration has been override - render_block b, cache_enabled: true # => This won't use fragment cache even when saying the helper to do it. Power for the users! + render_page_block b # => This won't use fragment cache sincs it's been disabled for the page and blocks configuration has been override + render_page_block b, cache_enabled: true # => This won't use fragment cache even when saying the helper to do it. Power for the users! ``` From f1a4162914553838fff6cd4a9ef70b2da8b801a4 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Mon, 5 Jan 2015 18:07:24 +0100 Subject: [PATCH 18/37] Documentation about the migration in another MD file --- README.md | 2 ++ doc/migration-blocks-steps.md | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 doc/migration-blocks-steps.md diff --git a/README.md b/README.md index 1f3b684..dfacb20 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ This `template` is set from the template attribute, being `show` the default val In a previous gem version blocks were a model within the NoCms::Pages namespace, but now everything was moved to the [nocms-blocks](https://github.com/simplelogica/nocms-blocks) and in this repo there's only left a rake task for the migration. +You can read the steps for a sucessful block migration in its own [migration documentation](doc/migration-blocks-steps.md) + ### Block Cache Blocks are rendered through the `render_page_block` helper instead of the `render_block` helper from `nocms-blocks`. This helper uses the `render_block` helper but add some extra cache levels: diff --git a/doc/migration-blocks-steps.md b/doc/migration-blocks-steps.md new file mode 100644 index 0000000..902b94d --- /dev/null +++ b/doc/migration-blocks-steps.md @@ -0,0 +1,11 @@ +These are the steps for the migration from NoCms::Pages::Block model to NoCms::Blocks::Block one + +1. *Change render_block for render_page_block*: This way, the helper we will be able to use the configuration about cache inside the own page. + +2. *Change all render that points to the no_cms/pages folder for the usual render_page_block*: If you have any `render partial: '...'` you should chante to the `render_page_block` helper, so you can benefit from the cache settings. + +3. *Change block templates from no_cms/pages folder to no_cms/blocks*: `render_block` and `render_page_blocks` will search the templates inside the no_cms/blocks views folder. + +4. If you want you can comment the `drop_table :no_cms_pages_blocks` inside the destroy_no_cms_pages_blocks migration. This way you won't delete that table and will always beable to recover the information. + +5. *Run the migrations*: the destroy_no_cms_pages_blocks migration will copy your information from the old blocks table to the new one and no information will be lost! From d84b139245fd616ae1e97a5c93b061615b41dc2f Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Mon, 5 Jan 2015 18:07:49 +0100 Subject: [PATCH 19/37] Avoiding to clear all content blocks on pages on the migration rake --- lib/tasks/pages_tasks.rake | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/tasks/pages_tasks.rake b/lib/tasks/pages_tasks.rake index 642afe5..84c13b8 100644 --- a/lib/tasks/pages_tasks.rake +++ b/lib/tasks/pages_tasks.rake @@ -4,7 +4,6 @@ namespace :no_cms do desc 'Task for migrating blocks from NoCms::Pages::Block model to NoCms::Blocks::Block' task :migrate_blocks => :environment do - NoCms::Pages::Page.all.each {|p| p.blocks.clear } root_blocks = NoCms::Pages::Deprecated::Block.dump root_blocks.each do |root_block| import_block root_block From ae96a22134dc5570f1ff0623a1c7006ece811f55 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Thu, 10 Sep 2015 13:05:09 +0200 Subject: [PATCH 20/37] Remove gem's migrations from dummy app. --- ...103350_create_no_cms_pages.no_cms_pages.rb | 15 ------------- ...03351_create_no_cms_blocks.no_cms_pages.rb | 17 -------------- ...ields_info_to_no_cms_block.no_cms_pages.rb | 6 ----- ...40_add_slug_to_no_cms_page.no_cms_pages.rb | 6 ----- ...nested_set_to_no_cms_pages.no_cms_pages.rb | 9 -------- ...54_add_path_to_no_cms_page.no_cms_pages.rb | 6 ----- ..._poisition_to_no_cms_block.no_cms_pages.rb | 6 ----- ...dd_template_to_no_cms_page.no_cms_pages.rb | 6 ----- ...3171429_add_draft_to_block.no_cms_pages.rb | 6 ----- ...4121241_add_draft_to_pages.no_cms_pages.rb | 6 ----- ...t_id_to_no_cms_pages_block.no_cms_pages.rb | 6 ----- ...ms_pages_page_translations.no_cms_pages.rb | 7 ------ ...ms_pages_page_translations.no_cms_pages.rb | 6 ----- ...ayout_to_no_cms_pages_page.no_cms_pages.rb | 6 ----- ...estroy_no_cms_pages_blocks.no_cms_pages.rb | 6 ----- ...eate_no_cms_blocks_blocks.no_cms_blocks.rb | 22 ------------------- ...sted_set_to_no_cms_blocks.no_cms_blocks.rb | 9 -------- ...on_to_no_cms_blocks_block.no_cms_blocks.rb | 6 ----- ...ocks_no_cms_pages_relation.no_cms_pages.rb | 12 ---------- 19 files changed, 163 deletions(-) delete mode 100644 spec/dummy/db/migrate/20140227103350_create_no_cms_pages.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140227103351_create_no_cms_blocks.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140227163905_add_fields_info_to_no_cms_block.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140228114240_add_slug_to_no_cms_page.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140303092928_add_awesome_nested_set_to_no_cms_pages.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140303100954_add_path_to_no_cms_page.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140303123920_add_poisition_to_no_cms_block.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140303175058_add_template_to_no_cms_page.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140313171429_add_draft_to_block.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140314121241_add_draft_to_pages.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140329161259_add_parent_id_to_no_cms_pages_block.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140407083148_add_css_class_and_id_to_no_cms_pages_page_translations.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140702114154_add_cache_enabled_to_no_cms_pages_page_translations.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20140806074938_add_layout_to_no_cms_pages_page.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20141211224504_destroy_no_cms_pages_blocks.no_cms_pages.rb delete mode 100644 spec/dummy/db/migrate/20141211224838_create_no_cms_blocks_blocks.no_cms_blocks.rb delete mode 100644 spec/dummy/db/migrate/20141211224839_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb delete mode 100644 spec/dummy/db/migrate/20141211224840_add_position_to_no_cms_blocks_block.no_cms_blocks.rb delete mode 100644 spec/dummy/db/migrate/20141211225408_create_no_cms_blocks_no_cms_pages_relation.no_cms_pages.rb diff --git a/spec/dummy/db/migrate/20140227103350_create_no_cms_pages.no_cms_pages.rb b/spec/dummy/db/migrate/20140227103350_create_no_cms_pages.no_cms_pages.rb deleted file mode 100644 index a7f8a32..0000000 --- a/spec/dummy/db/migrate/20140227103350_create_no_cms_pages.no_cms_pages.rb +++ /dev/null @@ -1,15 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140226123742) -class CreateNoCmsPages < ActiveRecord::Migration - def change - create_table :no_cms_pages_pages do |t| - t.timestamps - end - - create_table :no_cms_pages_page_translations do |t| - t.belongs_to :no_cms_pages_page, index: true - t.string :locale - t.string :title - t.string :body - end - end -end diff --git a/spec/dummy/db/migrate/20140227103351_create_no_cms_blocks.no_cms_pages.rb b/spec/dummy/db/migrate/20140227103351_create_no_cms_blocks.no_cms_pages.rb deleted file mode 100644 index 7d9efb6..0000000 --- a/spec/dummy/db/migrate/20140227103351_create_no_cms_blocks.no_cms_pages.rb +++ /dev/null @@ -1,17 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140227100626) -class CreateNoCmsBlocks < ActiveRecord::Migration - def change - create_table :no_cms_pages_blocks do |t| - t.belongs_to :page, index: true - - t.timestamps - end - - create_table :no_cms_pages_block_translations do |t| - t.belongs_to :no_cms_pages_block, index: true - t.string :locale - t.string :layout - end - - end -end diff --git a/spec/dummy/db/migrate/20140227163905_add_fields_info_to_no_cms_block.no_cms_pages.rb b/spec/dummy/db/migrate/20140227163905_add_fields_info_to_no_cms_block.no_cms_pages.rb deleted file mode 100644 index 6fdfd98..0000000 --- a/spec/dummy/db/migrate/20140227163905_add_fields_info_to_no_cms_block.no_cms_pages.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140227143723) -class AddFieldsInfoToNoCmsBlock < ActiveRecord::Migration - def change - add_column :no_cms_pages_block_translations, :fields_info, :longtext, default: Hash.new.to_yaml - end -end diff --git a/spec/dummy/db/migrate/20140228114240_add_slug_to_no_cms_page.no_cms_pages.rb b/spec/dummy/db/migrate/20140228114240_add_slug_to_no_cms_page.no_cms_pages.rb deleted file mode 100644 index c54e074..0000000 --- a/spec/dummy/db/migrate/20140228114240_add_slug_to_no_cms_page.no_cms_pages.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140228112643) -class AddSlugToNoCmsPage < ActiveRecord::Migration - def change - add_column :no_cms_pages_page_translations, :slug, :string - end -end diff --git a/spec/dummy/db/migrate/20140303092928_add_awesome_nested_set_to_no_cms_pages.no_cms_pages.rb b/spec/dummy/db/migrate/20140303092928_add_awesome_nested_set_to_no_cms_pages.no_cms_pages.rb deleted file mode 100644 index 9ecb1be..0000000 --- a/spec/dummy/db/migrate/20140303092928_add_awesome_nested_set_to_no_cms_pages.no_cms_pages.rb +++ /dev/null @@ -1,9 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140303092727) -class AddAwesomeNestedSetToNoCmsPages < ActiveRecord::Migration - def change - add_column :no_cms_pages_pages, :parent_id, :integer - add_column :no_cms_pages_pages, :lft, :integer - add_column :no_cms_pages_pages, :rgt, :integer - add_column :no_cms_pages_pages, :depth, :integer - end -end diff --git a/spec/dummy/db/migrate/20140303100954_add_path_to_no_cms_page.no_cms_pages.rb b/spec/dummy/db/migrate/20140303100954_add_path_to_no_cms_page.no_cms_pages.rb deleted file mode 100644 index fe5bc71..0000000 --- a/spec/dummy/db/migrate/20140303100954_add_path_to_no_cms_page.no_cms_pages.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140303100908) -class AddPathToNoCmsPage < ActiveRecord::Migration - def change - add_column :no_cms_pages_page_translations, :path, :string - end -end diff --git a/spec/dummy/db/migrate/20140303123920_add_poisition_to_no_cms_block.no_cms_pages.rb b/spec/dummy/db/migrate/20140303123920_add_poisition_to_no_cms_block.no_cms_pages.rb deleted file mode 100644 index d489559..0000000 --- a/spec/dummy/db/migrate/20140303123920_add_poisition_to_no_cms_block.no_cms_pages.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140303123845) -class AddPoisitionToNoCmsBlock < ActiveRecord::Migration - def change - add_column :no_cms_pages_blocks, :position, :integer - end -end diff --git a/spec/dummy/db/migrate/20140303175058_add_template_to_no_cms_page.no_cms_pages.rb b/spec/dummy/db/migrate/20140303175058_add_template_to_no_cms_page.no_cms_pages.rb deleted file mode 100644 index 55dd498..0000000 --- a/spec/dummy/db/migrate/20140303175058_add_template_to_no_cms_page.no_cms_pages.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140303145615) -class AddTemplateToNoCmsPage < ActiveRecord::Migration - def change - add_column :no_cms_pages_pages, :template, :string - end -end diff --git a/spec/dummy/db/migrate/20140313171429_add_draft_to_block.no_cms_pages.rb b/spec/dummy/db/migrate/20140313171429_add_draft_to_block.no_cms_pages.rb deleted file mode 100644 index 3b44137..0000000 --- a/spec/dummy/db/migrate/20140313171429_add_draft_to_block.no_cms_pages.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140313171000) -class AddDraftToBlock < ActiveRecord::Migration - def change - add_column :no_cms_pages_block_translations, :draft, :boolean, default: false - end -end diff --git a/spec/dummy/db/migrate/20140314121241_add_draft_to_pages.no_cms_pages.rb b/spec/dummy/db/migrate/20140314121241_add_draft_to_pages.no_cms_pages.rb deleted file mode 100644 index 4222d2c..0000000 --- a/spec/dummy/db/migrate/20140314121241_add_draft_to_pages.no_cms_pages.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140314110439) -class AddDraftToPages < ActiveRecord::Migration - def change - add_column :no_cms_pages_page_translations, :draft, :boolean, default: false - end -end diff --git a/spec/dummy/db/migrate/20140329161259_add_parent_id_to_no_cms_pages_block.no_cms_pages.rb b/spec/dummy/db/migrate/20140329161259_add_parent_id_to_no_cms_pages_block.no_cms_pages.rb deleted file mode 100644 index a760aa8..0000000 --- a/spec/dummy/db/migrate/20140329161259_add_parent_id_to_no_cms_pages_block.no_cms_pages.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140329160306) -class AddParentIdToNoCmsPagesBlock < ActiveRecord::Migration - def change - add_reference :no_cms_pages_blocks, :parent, index: true - end -end diff --git a/spec/dummy/db/migrate/20140407083148_add_css_class_and_id_to_no_cms_pages_page_translations.no_cms_pages.rb b/spec/dummy/db/migrate/20140407083148_add_css_class_and_id_to_no_cms_pages_page_translations.no_cms_pages.rb deleted file mode 100644 index e79735c..0000000 --- a/spec/dummy/db/migrate/20140407083148_add_css_class_and_id_to_no_cms_pages_page_translations.no_cms_pages.rb +++ /dev/null @@ -1,7 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140407083115) -class AddCssClassAndIdToNoCmsPagesPageTranslations < ActiveRecord::Migration - def change - add_column :no_cms_pages_page_translations, :css_class, :string - add_column :no_cms_pages_page_translations, :css_id, :string - end -end diff --git a/spec/dummy/db/migrate/20140702114154_add_cache_enabled_to_no_cms_pages_page_translations.no_cms_pages.rb b/spec/dummy/db/migrate/20140702114154_add_cache_enabled_to_no_cms_pages_page_translations.no_cms_pages.rb deleted file mode 100644 index d7a22d6..0000000 --- a/spec/dummy/db/migrate/20140702114154_add_cache_enabled_to_no_cms_pages_page_translations.no_cms_pages.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140702112813) -class AddCacheEnabledToNoCmsPagesPageTranslations < ActiveRecord::Migration - def change - add_column :no_cms_pages_page_translations, :cache_enabled, :boolean, default: true - end -end diff --git a/spec/dummy/db/migrate/20140806074938_add_layout_to_no_cms_pages_page.no_cms_pages.rb b/spec/dummy/db/migrate/20140806074938_add_layout_to_no_cms_pages_page.no_cms_pages.rb deleted file mode 100644 index 663ea0a..0000000 --- a/spec/dummy/db/migrate/20140806074938_add_layout_to_no_cms_pages_page.no_cms_pages.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_pages (originally 20140806074811) -class AddLayoutToNoCmsPagesPage < ActiveRecord::Migration - def change - add_column :no_cms_pages_pages, :layout, :string - end -end diff --git a/spec/dummy/db/migrate/20141211224504_destroy_no_cms_pages_blocks.no_cms_pages.rb b/spec/dummy/db/migrate/20141211224504_destroy_no_cms_pages_blocks.no_cms_pages.rb deleted file mode 100644 index 0a34a88..0000000 --- a/spec/dummy/db/migrate/20141211224504_destroy_no_cms_pages_blocks.no_cms_pages.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_pages (originally 20141211224348) -class DestroyNoCmsPagesBlocks < ActiveRecord::Migration - def change - drop_table :no_cms_pages_blocks - end -end diff --git a/spec/dummy/db/migrate/20141211224838_create_no_cms_blocks_blocks.no_cms_blocks.rb b/spec/dummy/db/migrate/20141211224838_create_no_cms_blocks_blocks.no_cms_blocks.rb deleted file mode 100644 index 3183b1d..0000000 --- a/spec/dummy/db/migrate/20141211224838_create_no_cms_blocks_blocks.no_cms_blocks.rb +++ /dev/null @@ -1,22 +0,0 @@ -# This migration comes from no_cms_blocks (originally 20140405135410) -# This migration comes from no_cms_blocks (originally 20140405135410) -class CreateNoCmsBlocksBlocks < ActiveRecord::Migration - def change - create_table :no_cms_blocks_blocks do |t| - - t.timestamps - end - - NoCms::Blocks::Block.translated_attribute_names = [:locale, :layout, :fields_info, :draft] - - create_table :no_cms_blocks_block_translations do |t| - t.belongs_to :no_cms_blocks_block - t.string :locale - t.string :layout - t.text :fields_info, :limit => 4294967295 - t.boolean :draft - end - - add_index :no_cms_blocks_block_translations, :no_cms_blocks_block_id, { name: 'no_cms_blocks_blocks_translations_block_id'} - end -end diff --git a/spec/dummy/db/migrate/20141211224839_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb b/spec/dummy/db/migrate/20141211224839_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb deleted file mode 100644 index 84d1e91..0000000 --- a/spec/dummy/db/migrate/20141211224839_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb +++ /dev/null @@ -1,9 +0,0 @@ -# This migration comes from no_cms_blocks (originally 20140405150944) -class AddAwesomeNestedSetToNoCmsBlocks < ActiveRecord::Migration - def change - add_column :no_cms_blocks_blocks, :parent_id, :integer - add_column :no_cms_blocks_blocks, :lft, :integer - add_column :no_cms_blocks_blocks, :rgt, :integer - add_column :no_cms_blocks_blocks, :depth, :integer - end -end diff --git a/spec/dummy/db/migrate/20141211224840_add_position_to_no_cms_blocks_block.no_cms_blocks.rb b/spec/dummy/db/migrate/20141211224840_add_position_to_no_cms_blocks_block.no_cms_blocks.rb deleted file mode 100644 index 3c150a8..0000000 --- a/spec/dummy/db/migrate/20141211224840_add_position_to_no_cms_blocks_block.no_cms_blocks.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This migration comes from no_cms_blocks (originally 20140618150651) -class AddPositionToNoCmsBlocksBlock < ActiveRecord::Migration - def change - add_column :no_cms_blocks_blocks, :position, :integer - end -end diff --git a/spec/dummy/db/migrate/20141211225408_create_no_cms_blocks_no_cms_pages_relation.no_cms_pages.rb b/spec/dummy/db/migrate/20141211225408_create_no_cms_blocks_no_cms_pages_relation.no_cms_pages.rb deleted file mode 100644 index 69d98ef..0000000 --- a/spec/dummy/db/migrate/20141211225408_create_no_cms_blocks_no_cms_pages_relation.no_cms_pages.rb +++ /dev/null @@ -1,12 +0,0 @@ -# This migration comes from no_cms_pages (originally 20141211225243) -class CreateNoCmsBlocksNoCmsPagesRelation < ActiveRecord::Migration - def change - create_table :no_cms_blocks_blocks_pages_pages, id: false do |t| - - t.belongs_to :page - t.belongs_to :block - - t.timestamps - end - end -end From 79bcbf54ae42c49ce84ebd7723f55f292a739963 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Thu, 10 Sep 2015 13:07:47 +0200 Subject: [PATCH 21/37] Add nocms-blocks migrations. --- ...eate_no_cms_blocks_blocks.no_cms_blocks.rb | 22 +++++++++++++++++++ ...sted_set_to_no_cms_blocks.no_cms_blocks.rb | 9 ++++++++ ...on_to_no_cms_blocks_block.no_cms_blocks.rb | 6 +++++ ...fo_to_no_cms_blocks_block.no_cms_blocks.rb | 6 +++++ ...s_to_no_cms_blocks_blocks.no_cms_blocks.rb | 20 +++++++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 db/migrate/20141211224242_create_no_cms_blocks_blocks.no_cms_blocks.rb create mode 100644 db/migrate/20150909142451_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb create mode 100644 db/migrate/20150909142452_add_position_to_no_cms_blocks_block.no_cms_blocks.rb create mode 100644 db/migrate/20150909142453_add_non_translated_fields_info_to_no_cms_blocks_block.no_cms_blocks.rb create mode 100644 db/migrate/20150909142454_move_layout_from_no_cms_blocks_block_translations_to_no_cms_blocks_blocks.no_cms_blocks.rb diff --git a/db/migrate/20141211224242_create_no_cms_blocks_blocks.no_cms_blocks.rb b/db/migrate/20141211224242_create_no_cms_blocks_blocks.no_cms_blocks.rb new file mode 100644 index 0000000..3183b1d --- /dev/null +++ b/db/migrate/20141211224242_create_no_cms_blocks_blocks.no_cms_blocks.rb @@ -0,0 +1,22 @@ +# This migration comes from no_cms_blocks (originally 20140405135410) +# This migration comes from no_cms_blocks (originally 20140405135410) +class CreateNoCmsBlocksBlocks < ActiveRecord::Migration + def change + create_table :no_cms_blocks_blocks do |t| + + t.timestamps + end + + NoCms::Blocks::Block.translated_attribute_names = [:locale, :layout, :fields_info, :draft] + + create_table :no_cms_blocks_block_translations do |t| + t.belongs_to :no_cms_blocks_block + t.string :locale + t.string :layout + t.text :fields_info, :limit => 4294967295 + t.boolean :draft + end + + add_index :no_cms_blocks_block_translations, :no_cms_blocks_block_id, { name: 'no_cms_blocks_blocks_translations_block_id'} + end +end diff --git a/db/migrate/20150909142451_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb b/db/migrate/20150909142451_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb new file mode 100644 index 0000000..84d1e91 --- /dev/null +++ b/db/migrate/20150909142451_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb @@ -0,0 +1,9 @@ +# This migration comes from no_cms_blocks (originally 20140405150944) +class AddAwesomeNestedSetToNoCmsBlocks < ActiveRecord::Migration + def change + add_column :no_cms_blocks_blocks, :parent_id, :integer + add_column :no_cms_blocks_blocks, :lft, :integer + add_column :no_cms_blocks_blocks, :rgt, :integer + add_column :no_cms_blocks_blocks, :depth, :integer + end +end diff --git a/db/migrate/20150909142452_add_position_to_no_cms_blocks_block.no_cms_blocks.rb b/db/migrate/20150909142452_add_position_to_no_cms_blocks_block.no_cms_blocks.rb new file mode 100644 index 0000000..3c150a8 --- /dev/null +++ b/db/migrate/20150909142452_add_position_to_no_cms_blocks_block.no_cms_blocks.rb @@ -0,0 +1,6 @@ +# This migration comes from no_cms_blocks (originally 20140618150651) +class AddPositionToNoCmsBlocksBlock < ActiveRecord::Migration + def change + add_column :no_cms_blocks_blocks, :position, :integer + end +end diff --git a/db/migrate/20150909142453_add_non_translated_fields_info_to_no_cms_blocks_block.no_cms_blocks.rb b/db/migrate/20150909142453_add_non_translated_fields_info_to_no_cms_blocks_block.no_cms_blocks.rb new file mode 100644 index 0000000..8a05f8e --- /dev/null +++ b/db/migrate/20150909142453_add_non_translated_fields_info_to_no_cms_blocks_block.no_cms_blocks.rb @@ -0,0 +1,6 @@ +# This migration comes from no_cms_blocks (originally 20150709132202) +class AddNonTranslatedFieldsInfoToNoCmsBlocksBlock < ActiveRecord::Migration + def change + add_column :no_cms_blocks_blocks, :fields_info, :longtext + end +end diff --git a/db/migrate/20150909142454_move_layout_from_no_cms_blocks_block_translations_to_no_cms_blocks_blocks.no_cms_blocks.rb b/db/migrate/20150909142454_move_layout_from_no_cms_blocks_block_translations_to_no_cms_blocks_blocks.no_cms_blocks.rb new file mode 100644 index 0000000..be97232 --- /dev/null +++ b/db/migrate/20150909142454_move_layout_from_no_cms_blocks_block_translations_to_no_cms_blocks_blocks.no_cms_blocks.rb @@ -0,0 +1,20 @@ +# This migration comes from no_cms_blocks (originally 20150710112549) +class MoveLayoutFromNoCmsBlocksBlockTranslationsToNoCmsBlocksBlocks < ActiveRecord::Migration + def up + add_column :no_cms_blocks_blocks, :layout, :string + + NoCms::Blocks::Block::Translation.all.each do |translation| + translation.globalized_model.update_column layout: translation.layout + end + + remove_column :no_cms_blocks_block_translations, :layout, :string + end + + def down + add_column :no_cms_blocks_block_translations, :layout, :string + NoCms::Blocks::Block::Translation.all.each do |translation| + translation.update_column layout: translation.globalized_model.layout + end + remove_column :no_cms_blocks_blocks, :layout, :string + end +end From 5d16bd629e1ccc255e1280364442e3381eac066a Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Thu, 10 Sep 2015 13:08:03 +0200 Subject: [PATCH 22/37] Fix migration. --- db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb b/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb index 585e5ab..ee15b47 100644 --- a/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb +++ b/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb @@ -5,7 +5,11 @@ def change raise Exception.new("Migration destroying no_cms_pages_blocks should only be run after creating NoCms::Blocks::Block table") end - Rake::Task["no_cms:pages:migrate_blocks"].invoke + begin + Rake::Task["no_cms:pages:migrate_blocks"].invoke + rescue + Rake::Task["app:no_cms:pages:migrate_blocks"].invoke + end drop_table :no_cms_pages_blocks end end From 88dd7106d0b5515c5165e1c1a1c4217d7e55e841 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Thu, 10 Sep 2015 13:09:20 +0200 Subject: [PATCH 23/37] Move layout config from pages to blocks on dummy app. --- .../dummy/config/initializers/nocms/blocks.rb | 26 +++++++++++++++++++ spec/dummy/config/initializers/nocms/pages.rb | 26 ------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/spec/dummy/config/initializers/nocms/blocks.rb b/spec/dummy/config/initializers/nocms/blocks.rb index 479efac..ee0a4fd 100644 --- a/spec/dummy/config/initializers/nocms/blocks.rb +++ b/spec/dummy/config/initializers/nocms/blocks.rb @@ -40,4 +40,30 @@ # } # config.block_layouts = {} + config.block_layouts = { + 'default' => { + template: 'default', + fields: { + title: :string, + body: :text + } + }, + 'title-3_columns' => { + template: 'title_3_columns', + fields: { + title: :string, + column_1: :text, + column_2: :text, + column_3: :text + }, + }, + 'logo-caption' => { + template: 'logo_caption', + fields: { + caption: :string, + logo: TestImage + } + } + } + end diff --git a/spec/dummy/config/initializers/nocms/pages.rb b/spec/dummy/config/initializers/nocms/pages.rb index a4fe003..22cc220 100644 --- a/spec/dummy/config/initializers/nocms/pages.rb +++ b/spec/dummy/config/initializers/nocms/pages.rb @@ -28,32 +28,6 @@ # } # config.block_layouts = {} - config.block_layouts = { - 'default' => { - template: 'default', - fields: { - title: :string, - body: :text - } - }, - 'title-3_columns' => { - template: 'title_3_columns', - fields: { - title: :string, - column_1: :text, - column_2: :text, - column_3: :text - }, - }, - 'logo-caption' => { - template: 'logo_caption', - fields: { - caption: :string, - logo: TestImage - } - } - } - # By default we use all the layouts in the app/views/layouts from the app # config.page_layouts = ['application', ...] From 32e857e246a0f04fb6053d7b238b9ec22a26e4d3 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Thu, 10 Sep 2015 13:10:08 +0200 Subject: [PATCH 24/37] Update dummy app's schema. --- spec/dummy/db/schema.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 8230783..7a38e96 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -11,12 +11,11 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141211225408) do +ActiveRecord::Schema.define(version: 20150909142454) do create_table "no_cms_blocks_block_translations", force: true do |t| t.integer "no_cms_blocks_block_id" t.string "locale" - t.string "layout" t.text "fields_info", limit: 4294967295 t.boolean "draft" end @@ -31,6 +30,8 @@ t.integer "rgt" t.integer "depth" t.integer "position" + t.text "fields_info" + t.string "layout" end create_table "no_cms_blocks_blocks_pages_pages", id: false, force: true do |t| @@ -44,7 +45,7 @@ t.integer "no_cms_pages_block_id" t.string "locale" t.string "layout" - t.text "fields_info", default: "--- {}\n" + t.text "fields_info" t.boolean "draft", default: false end From b708fdf7d3e3cdf49c49b8a087f548b72658459e Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Thu, 10 Sep 2015 13:13:34 +0200 Subject: [PATCH 25/37] Change NoCms::Pages::Block by NoCms::Blocks::Block Delete nocms-blocks instead nocms-pages blocks on dummy app's seeds --- spec/dummy/db/seeds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/dummy/db/seeds.rb b/spec/dummy/db/seeds.rb index 7f60cdf..c08b281 100644 --- a/spec/dummy/db/seeds.rb +++ b/spec/dummy/db/seeds.rb @@ -1,5 +1,5 @@ NoCms::Pages::Page.delete_all -NoCms::Pages::Block.delete_all +NoCms::Blocks::Block.delete_all NoCms::Pages::Page.create!( title: Faker::Lorem.sentence, From 03dfc6fff09ccb0eaa9c49d3b00b93810ea87832 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Thu, 10 Sep 2015 13:16:35 +0200 Subject: [PATCH 26/37] Add fixes to page model. - Check if title exists before generates slug. - Check if the page is persisted before rebuild its path. --- app/models/no_cms/pages/page.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/no_cms/pages/page.rb b/app/models/no_cms/pages/page.rb index dbbeb91..b458422 100644 --- a/app/models/no_cms/pages/page.rb +++ b/app/models/no_cms/pages/page.rb @@ -28,14 +28,18 @@ def self.home def set_slug_and_path self.slug = title.parameterize if slug.nil? && !title.nil? # If there's no slug then we create it - self.slug = title.parameterize if slug.blank? && !parent.nil? # If slug is blank and this page has a parent then we recreate it - self.slug = title.parameterize if slug.blank? && Page.home && (Page.home != self) # If slug is blank and there's already a home (and it's another page) then we recreate it + self.slug = title.parameterize if slug.blank? && !title.nil? && !parent.nil? # If slug is blank and this page has a parent then we recreate it + self.slug = title.parameterize if slug.blank? && !title.nil? && Page.home && (Page.home != self) # If slug is blank and there's already a home (and it's another page) then we recreate it self.rebuild_path if path.nil? || attribute_changed?('slug') end def rebuild_path - self.update_attribute :path, "#{parent.path unless parent.nil?}/#{slug}" - descendants.each(&:rebuild_path) + if self.persisted? + self.update_attribute :path, "#{parent.path unless parent.nil?}/#{slug}" + descendants.each(&:rebuild_path) + else + self.path = "#{parent.path unless parent.nil?}/#{slug}" + end end def self.templates From d506497390e6f03a33ff78ae247e3edc81907144 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Thu, 10 Sep 2015 13:18:02 +0200 Subject: [PATCH 27/37] Include dummy app task to Rakefile. --- Rakefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 84becba..33383f8 100644 --- a/Rakefile +++ b/Rakefile @@ -14,8 +14,11 @@ RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_files.include('lib/**/*.rb') end +Bundler::GemHelper.install_tasks - +APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) +load 'rails/tasks/engine.rake' Bundler::GemHelper.install_tasks +task :default => [:"app:spec"] From fa42a34b42bdfe6f4ffd39dcdfdbad986551a718 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Thu, 10 Sep 2015 16:01:34 +0200 Subject: [PATCH 28/37] Update generators. --- lib/generators/nocms/pages_generator.rb | 4 ++ .../config/initializers/nocms/pages.rb | 40 ------------------- .../dummy/config/initializers/nocms/blocks.rb | 8 ++++ spec/dummy/config/initializers/nocms/pages.rb | 31 +------------- 4 files changed, 14 insertions(+), 69 deletions(-) diff --git a/lib/generators/nocms/pages_generator.rb b/lib/generators/nocms/pages_generator.rb index cbf8cf8..f7d4abf 100644 --- a/lib/generators/nocms/pages_generator.rb +++ b/lib/generators/nocms/pages_generator.rb @@ -7,6 +7,10 @@ def generate_nocms_pages_initializer template "config/initializers/nocms/pages.rb", File.join(destination_root, "config", "initializers", "nocms", "pages.rb") end + def generate_nocms_blocks_initializer + generate "nocms:blocks" + end + def self.namespace "nocms:pages" end diff --git a/lib/generators/nocms/templates/config/initializers/nocms/pages.rb b/lib/generators/nocms/templates/config/initializers/nocms/pages.rb index dda00cc..d189827 100644 --- a/lib/generators/nocms/templates/config/initializers/nocms/pages.rb +++ b/lib/generators/nocms/templates/config/initializers/nocms/pages.rb @@ -1,45 +1,5 @@ NoCms::Pages.configure do |config| - # Enable Rails fragment cache for the block templates when you call the render_block helper - # You can override this cache setting in any block configuration below or sending - # the cache option true or false when calling the block helpers - # e.g: render_block block, cache: true - # config.cache_enabled = false - - # In this section we configure block layouts. It's just an array of layouts, each consisting on a hash. - # Each layout has a series of options - # E.g: config.block_layouts = { - # 'title-long_text' => { - # template: 'title-long_text', # This is the template of this block, - # # used as a partial both in the front - # # and the admin (if you use the nocms-admin-pages gem) - # fields: { # This is the list of fields a block with this layout would have - # title: :string, - # long_text: :text, - # image: Image, # You may use another ActiveRecord classes of your own - # } - # allow_nested_blocks: true, # A block with this layout may include a list of nested blocks - # # This setting is actually used by nocms-admin-pages gem to show - # # nested forms - # nest_levels: [0] # Some layout may not be nestable, or useful only in certain nesting level - # # Once again, this setting is used by nocms-admin-pages gem to hide certain - # # in nested blocks. When blank, it's assumed there's no restriction. - # cache_enabled: false # When setting cache_enabled you will be **overriding** the global cache_enabled - # # setting. If you don't set a cache setting then it will use the global cache - # # setting specified above - # }, - # 'title-3_columns_text' => { - # template: 'title-3_columns_text', - # fields: { - # title: :string, - # column_1: :text, - # column_2: :text, - # column_3: :text - # } - # } - # } - # config.block_layouts = {} - # By default we use blocks to create the content of the page. If we just want a big textarea to insert the content we must set use_body to true # config.use_body = false diff --git a/spec/dummy/config/initializers/nocms/blocks.rb b/spec/dummy/config/initializers/nocms/blocks.rb index ee0a4fd..482fc16 100644 --- a/spec/dummy/config/initializers/nocms/blocks.rb +++ b/spec/dummy/config/initializers/nocms/blocks.rb @@ -17,6 +17,14 @@ # title: :string, # long_text: :text, # image: Image, # You may use another ActiveRecord classes of your own + # column: { # You can configure the block with more options than just + # # the type of the field. If you use the "quick" configuration + # # all other settings will get the default value + # type: :text, # The type of the field, just as explained before + # translated: true # If the field must store different values for + # # each translation. By default every field is + # # translated + # } # } # allow_nested_blocks: true, # A block with this layout may include a list of nested blocks # # This setting is actually used by nocms-admin gem to show diff --git a/spec/dummy/config/initializers/nocms/pages.rb b/spec/dummy/config/initializers/nocms/pages.rb index 22cc220..b88b9c4 100644 --- a/spec/dummy/config/initializers/nocms/pages.rb +++ b/spec/dummy/config/initializers/nocms/pages.rb @@ -1,36 +1,9 @@ NoCms::Pages.configure do |config| - # Enable Rails fragment cache for the block templates when you call the render_block helper - # You can override this cache setting in any block configuration below or sending - # the cache option true or false when calling the menu helpers - # e.g: render_block block, cache: true - # config.cache_enabled = false - - # In this section we configure block layouts. It's just an array of layouts, each consisting on a hash. - # Each layout has a template and a list of fields with a type. - # E.g: config.block_layouts = { - # 'title-long_text' => { - # template: 'title-long_text', - # fields: { - # title: :string, - # long_text: :text - # } - # }, - # 'title-3_columns_text' => { - # template: 'title-3_columns_text', - # fields: { - # title: :string, - # column_1: :text, - # column_2: :text, - # column_3: :text - # } - # } - # } - # config.block_layouts = {} + # By default we use blocks to create the content of the page. If we just want a big textarea to insert the content we must set use_body to true + config.use_body = true # By default we use all the layouts in the app/views/layouts from the app # config.page_layouts = ['application', ...] - config.use_body = true - end From 2442bd0239d039abe4c76e2904b26b0ec7efb7f6 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Thu, 10 Sep 2015 16:03:12 +0200 Subject: [PATCH 29/37] Update nocms-blocks dependency. --- Gemfile | 2 -- Gemfile.lock | 26 ++++++++++---------------- pages.gemspec | 2 +- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index 62f4943..fbefdb3 100644 --- a/Gemfile +++ b/Gemfile @@ -24,5 +24,3 @@ group :test do gem 'capybara' gem 'database_cleaner' end - -gem "nocms-blocks", git: 'git@github.com:simplelogica/nocms-blocks.git', branch: 'master' diff --git a/Gemfile.lock b/Gemfile.lock index 80d275b..bf90f93 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,19 +1,10 @@ -GIT - remote: git@github.com:simplelogica/nocms-blocks.git - revision: efb13dcfcd324a862612e0f024d0ba6ed319a296 - branch: master - specs: - nocms-blocks (0.0.1) - awesome_nested_set (>= 3.0.0.rc.6) - rails (~> 4.0, >= 4.0.3) - PATH remote: . specs: - nocms-pages (0.0.1) + nocms-pages (0.1.0) awesome_nested_set (>= 3.0.0.rc.6) globalize (~> 4.0, >= 4.0.0) - nocms-blocks + nocms-blocks (~> 1.1.1) rails (~> 4.0, >= 4.0.3) GEM @@ -36,7 +27,7 @@ GEM activerecord-deprecated_finders (~> 1.0.2) activesupport (= 4.0.3) arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.3) + activerecord-deprecated_finders (1.0.4) activesupport (4.0.3) i18n (~> 0.6, >= 0.6.4) minitest (~> 4.2) @@ -44,7 +35,7 @@ GEM thread_safe (~> 0.1) tzinfo (~> 0.3.37) arel (4.0.2) - awesome_nested_set (3.0.1) + awesome_nested_set (3.0.2) activerecord (>= 4.0.0, < 5) builder (3.1.4) capybara (2.2.1) @@ -65,7 +56,7 @@ GEM activesupport (>= 3.0.0) faker (1.2.0) i18n (~> 0.5) - globalize (4.0.1) + globalize (4.0.3) activemodel (>= 4.0.0, < 5) activerecord (>= 4.0.0, < 5) hike (1.2.3) @@ -78,6 +69,10 @@ GEM mini_portile (0.5.2) minitest (4.7.5) multi_json (1.10.1) + nocms-blocks (1.1.1) + awesome_nested_set (~> 3.0.0) + globalize (>= 4.0.0, < 5.1) + rails (~> 4.0, <= 4.2.3) nokogiri (1.6.1) mini_portile (~> 0.5.0) polyglot (0.3.5) @@ -118,7 +113,7 @@ GEM rspec-mocks (= 3.0.0.beta2) rspec-support (= 3.0.0.beta2) rspec-support (3.0.0.beta2) - sprockets (2.12.3) + sprockets (2.12.4) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) @@ -147,7 +142,6 @@ DEPENDENCIES database_cleaner factory_girl faker - nocms-blocks! nocms-pages! rspec-rails (~> 3.0.0.beta) sqlite3 diff --git a/pages.gemspec b/pages.gemspec index d47fdeb..b64ae32 100644 --- a/pages.gemspec +++ b/pages.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.add_dependency "rails", '~> 4.0', '>= 4.0.3' s.add_dependency "globalize", '~> 4.0', '>= 4.0.0' s.add_dependency "awesome_nested_set", '>= 3.0.0.rc.6' - s.add_dependency "nocms-blocks" + s.add_dependency "nocms-blocks", '~> 1.1.1' s.add_development_dependency "sqlite3" end From 271ea37776718926b1c5901c392ef4322be57e26 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Fri, 11 Sep 2015 10:24:17 +0200 Subject: [PATCH 30/37] Fix Gem::Package::TooLongFileName error. - Move blocks migrations to dummy app to fix Gem::Package::TooLongFileName error on gem building. - Fix DestroyNoCmsPagesBlocks migration. - Update readme. --- README.md | 1 + .../20141211224348_destroy_no_cms_pages_blocks.rb | 14 +++++++------- ...21_create_no_cms_blocks_blocks.no_cms_blocks.rb | 0 ...me_nested_set_to_no_cms_blocks.no_cms_blocks.rb | 0 ...osition_to_no_cms_blocks_block.no_cms_blocks.rb | 0 ...ds_info_to_no_cms_blocks_block.no_cms_blocks.rb | 0 ...ations_to_no_cms_blocks_blocks.no_cms_blocks.rb | 0 spec/dummy/db/schema.rb | 2 +- 8 files changed, 9 insertions(+), 8 deletions(-) rename db/migrate/20141211224242_create_no_cms_blocks_blocks.no_cms_blocks.rb => spec/dummy/db/migrate/20150910163021_create_no_cms_blocks_blocks.no_cms_blocks.rb (100%) rename db/migrate/20150909142451_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb => spec/dummy/db/migrate/20150910163022_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb (100%) rename db/migrate/20150909142452_add_position_to_no_cms_blocks_block.no_cms_blocks.rb => spec/dummy/db/migrate/20150910163023_add_position_to_no_cms_blocks_block.no_cms_blocks.rb (100%) rename db/migrate/20150909142453_add_non_translated_fields_info_to_no_cms_blocks_block.no_cms_blocks.rb => spec/dummy/db/migrate/20150910163024_add_non_translated_fields_info_to_no_cms_blocks_block.no_cms_blocks.rb (100%) rename db/migrate/20150909142454_move_layout_from_no_cms_blocks_block_translations_to_no_cms_blocks_blocks.no_cms_blocks.rb => spec/dummy/db/migrate/20150910163025_move_layout_from_no_cms_blocks_block_translations_to_no_cms_blocks_blocks.no_cms_blocks.rb (100%) diff --git a/README.md b/README.md index c045581..bf747ea 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ bundle install And then import all the migrations: ``` +rake no_cms_blocks:install:migrations rake no_cms_pages:install:migrations ``` diff --git a/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb b/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb index ee15b47..d16a3a1 100644 --- a/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb +++ b/db/migrate/20141211224348_destroy_no_cms_pages_blocks.rb @@ -1,15 +1,15 @@ class DestroyNoCmsPagesBlocks < ActiveRecord::Migration def change - if !defined?(NoCms::Blocks::Block) || !NoCms::Blocks::Block.table_exists? - raise Exception.new("Migration destroying no_cms_pages_blocks should only be run after creating NoCms::Blocks::Block table") + if NoCms::Blocks::Block.table_exists? + begin + Rake::Task["no_cms:pages:migrate_blocks"].invoke + rescue + Rake::Task["app:no_cms:pages:migrate_blocks"].invoke + end end - begin - Rake::Task["no_cms:pages:migrate_blocks"].invoke - rescue - Rake::Task["app:no_cms:pages:migrate_blocks"].invoke - end drop_table :no_cms_pages_blocks + end end diff --git a/db/migrate/20141211224242_create_no_cms_blocks_blocks.no_cms_blocks.rb b/spec/dummy/db/migrate/20150910163021_create_no_cms_blocks_blocks.no_cms_blocks.rb similarity index 100% rename from db/migrate/20141211224242_create_no_cms_blocks_blocks.no_cms_blocks.rb rename to spec/dummy/db/migrate/20150910163021_create_no_cms_blocks_blocks.no_cms_blocks.rb diff --git a/db/migrate/20150909142451_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb b/spec/dummy/db/migrate/20150910163022_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb similarity index 100% rename from db/migrate/20150909142451_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb rename to spec/dummy/db/migrate/20150910163022_add_awesome_nested_set_to_no_cms_blocks.no_cms_blocks.rb diff --git a/db/migrate/20150909142452_add_position_to_no_cms_blocks_block.no_cms_blocks.rb b/spec/dummy/db/migrate/20150910163023_add_position_to_no_cms_blocks_block.no_cms_blocks.rb similarity index 100% rename from db/migrate/20150909142452_add_position_to_no_cms_blocks_block.no_cms_blocks.rb rename to spec/dummy/db/migrate/20150910163023_add_position_to_no_cms_blocks_block.no_cms_blocks.rb diff --git a/db/migrate/20150909142453_add_non_translated_fields_info_to_no_cms_blocks_block.no_cms_blocks.rb b/spec/dummy/db/migrate/20150910163024_add_non_translated_fields_info_to_no_cms_blocks_block.no_cms_blocks.rb similarity index 100% rename from db/migrate/20150909142453_add_non_translated_fields_info_to_no_cms_blocks_block.no_cms_blocks.rb rename to spec/dummy/db/migrate/20150910163024_add_non_translated_fields_info_to_no_cms_blocks_block.no_cms_blocks.rb diff --git a/db/migrate/20150909142454_move_layout_from_no_cms_blocks_block_translations_to_no_cms_blocks_blocks.no_cms_blocks.rb b/spec/dummy/db/migrate/20150910163025_move_layout_from_no_cms_blocks_block_translations_to_no_cms_blocks_blocks.no_cms_blocks.rb similarity index 100% rename from db/migrate/20150909142454_move_layout_from_no_cms_blocks_block_translations_to_no_cms_blocks_blocks.no_cms_blocks.rb rename to spec/dummy/db/migrate/20150910163025_move_layout_from_no_cms_blocks_block_translations_to_no_cms_blocks_blocks.no_cms_blocks.rb diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 7a38e96..f87292f 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150909142454) do +ActiveRecord::Schema.define(version: 20150910163025) do create_table "no_cms_blocks_block_translations", force: true do |t| t.integer "no_cms_blocks_block_id" From e333f1db0fe76e0b437261dc441fe3eaf8c7d553 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Fri, 11 Sep 2015 10:26:25 +0200 Subject: [PATCH 31/37] Add apprailsal gem. --- Gemfile | 1 + Gemfile.lock | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Gemfile b/Gemfile index fbefdb3..a83fd7f 100644 --- a/Gemfile +++ b/Gemfile @@ -23,4 +23,5 @@ group :test do gem 'factory_girl' gem 'capybara' gem 'database_cleaner' + gem 'appraisal' end diff --git a/Gemfile.lock b/Gemfile.lock index bf90f93..bbc2f90 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -34,6 +34,10 @@ GEM multi_json (~> 1.3) thread_safe (~> 0.1) tzinfo (~> 0.3.37) + appraisal (2.1.0) + bundler + rake + thor (>= 0.14.0) arel (4.0.2) awesome_nested_set (3.0.2) activerecord (>= 4.0.0, < 5) @@ -137,6 +141,7 @@ PLATFORMS ruby DEPENDENCIES + appraisal capybara carrierwave database_cleaner From 1ea47a58168c73573996f50b2f5575654155b4af Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Fri, 11 Sep 2015 10:28:03 +0200 Subject: [PATCH 32/37] Update globalize dependency. --- Gemfile.lock | 2 +- pages.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index bbc2f90..534bb5b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,7 +3,7 @@ PATH specs: nocms-pages (0.1.0) awesome_nested_set (>= 3.0.0.rc.6) - globalize (~> 4.0, >= 4.0.0) + globalize (>= 4.0.0, < 5.1) nocms-blocks (~> 1.1.1) rails (~> 4.0, >= 4.0.3) diff --git a/pages.gemspec b/pages.gemspec index b64ae32..c4b623c 100644 --- a/pages.gemspec +++ b/pages.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "LICENSE", "Rakefile", "README.md"] s.add_dependency "rails", '~> 4.0', '>= 4.0.3' - s.add_dependency "globalize", '~> 4.0', '>= 4.0.0' + s.add_dependency "globalize", '>= 4.0.0', '< 5.1' s.add_dependency "awesome_nested_set", '>= 3.0.0.rc.6' s.add_dependency "nocms-blocks", '~> 1.1.1' From 22a9599eb844814bfc5eb65668b5b605db73847d Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Fri, 11 Sep 2015 10:29:39 +0200 Subject: [PATCH 33/37] Add appraisal config. --- Appraisals | 11 +++ gemfiles/rails_4_0.gemfile | 20 ++++ gemfiles/rails_4_0.gemfile.lock | 139 +++++++++++++++++++++++++++ gemfiles/rails_4_1.gemfile | 20 ++++ gemfiles/rails_4_1.gemfile.lock | 143 +++++++++++++++++++++++++++ gemfiles/rails_4_2.gemfile | 20 ++++ gemfiles/rails_4_2.gemfile.lock | 165 ++++++++++++++++++++++++++++++++ 7 files changed, 518 insertions(+) create mode 100644 Appraisals create mode 100644 gemfiles/rails_4_0.gemfile create mode 100644 gemfiles/rails_4_0.gemfile.lock create mode 100644 gemfiles/rails_4_1.gemfile create mode 100644 gemfiles/rails_4_1.gemfile.lock create mode 100644 gemfiles/rails_4_2.gemfile create mode 100644 gemfiles/rails_4_2.gemfile.lock diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..32784b3 --- /dev/null +++ b/Appraisals @@ -0,0 +1,11 @@ +appraise "rails-4-0" do + gem "rails", "4.0.13" +end + +appraise "rails-4-1" do + gem "rails", "4.1.13" +end + +appraise "rails-4-2" do + gem "rails", "4.2.3" +end diff --git a/gemfiles/rails_4_0.gemfile b/gemfiles/rails_4_0.gemfile new file mode 100644 index 0000000..9a244ec --- /dev/null +++ b/gemfiles/rails_4_0.gemfile @@ -0,0 +1,20 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "4.0.13" + +group :development, :test do + gem "faker" + gem "carrierwave" +end + +group :test do + gem "rspec-rails", "~> 3.0.0.beta" + gem "factory_girl" + gem "capybara" + gem "database_cleaner" + gem "appraisal" +end + +gemspec :path => "../" diff --git a/gemfiles/rails_4_0.gemfile.lock b/gemfiles/rails_4_0.gemfile.lock new file mode 100644 index 0000000..9e293cb --- /dev/null +++ b/gemfiles/rails_4_0.gemfile.lock @@ -0,0 +1,139 @@ +PATH + remote: ../ + specs: + nocms-pages (0.1.0) + awesome_nested_set (>= 3.0.0.rc.6) + globalize (>= 4.0.0, < 5.1) + nocms-blocks (~> 1.1.1) + rails (~> 4.0, >= 4.0.3) + +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.0.13) + actionpack (= 4.0.13) + mail (~> 2.5, >= 2.5.4) + actionpack (4.0.13) + activesupport (= 4.0.13) + builder (~> 3.1.0) + erubis (~> 2.7.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + activemodel (4.0.13) + activesupport (= 4.0.13) + builder (~> 3.1.0) + activerecord (4.0.13) + activemodel (= 4.0.13) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.13) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.4) + activesupport (4.0.13) + i18n (~> 0.6, >= 0.6.9) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) + appraisal (2.1.0) + bundler + rake + thor (>= 0.14.0) + arel (4.0.2) + awesome_nested_set (3.0.2) + activerecord (>= 4.0.0, < 5) + builder (3.1.4) + capybara (2.5.0) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + carrierwave (0.10.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) + mime-types (>= 1.16) + database_cleaner (1.5.0) + diff-lcs (1.2.5) + erubis (2.7.0) + factory_girl (4.5.0) + activesupport (>= 3.0.0) + faker (1.5.0) + i18n (~> 0.5) + globalize (4.0.3) + activemodel (>= 4.0.0, < 5) + activerecord (>= 4.0.0, < 5) + i18n (0.7.0) + json (1.8.3) + mail (2.6.3) + mime-types (>= 1.16, < 3) + mime-types (2.6.1) + mini_portile (0.6.2) + minitest (4.7.5) + multi_json (1.11.2) + nocms-blocks (1.1.1) + awesome_nested_set (~> 3.0.0) + globalize (>= 4.0.0, < 5.1) + rails (~> 4.0, <= 4.2.3) + nokogiri (1.6.6.2) + mini_portile (~> 0.6.0) + rack (1.5.5) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.0.13) + actionmailer (= 4.0.13) + actionpack (= 4.0.13) + activerecord (= 4.0.13) + activesupport (= 4.0.13) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.13) + sprockets-rails (~> 2.0) + railties (4.0.13) + actionpack (= 4.0.13) + activesupport (= 4.0.13) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.4.2) + rspec-core (3.0.4) + rspec-support (~> 3.0.0) + rspec-expectations (3.0.4) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.0.0) + rspec-mocks (3.0.4) + rspec-support (~> 3.0.0) + rspec-rails (3.0.2) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-support (~> 3.0.0) + rspec-support (3.0.4) + sprockets (3.3.4) + rack (~> 1.0) + sprockets-rails (2.3.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (>= 2.8, < 4.0) + sqlite3 (1.3.10) + thor (0.19.1) + thread_safe (0.3.5) + tzinfo (0.3.44) + xpath (2.0.0) + nokogiri (~> 1.3) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + capybara + carrierwave + database_cleaner + factory_girl + faker + nocms-pages! + rails (= 4.0.13) + rspec-rails (~> 3.0.0.beta) + sqlite3 diff --git a/gemfiles/rails_4_1.gemfile b/gemfiles/rails_4_1.gemfile new file mode 100644 index 0000000..d4cd06b --- /dev/null +++ b/gemfiles/rails_4_1.gemfile @@ -0,0 +1,20 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "4.1.13" + +group :development, :test do + gem "faker" + gem "carrierwave" +end + +group :test do + gem "rspec-rails", "~> 3.0.0.beta" + gem "factory_girl" + gem "capybara" + gem "database_cleaner" + gem "appraisal" +end + +gemspec :path => "../" diff --git a/gemfiles/rails_4_1.gemfile.lock b/gemfiles/rails_4_1.gemfile.lock new file mode 100644 index 0000000..1ad6ab6 --- /dev/null +++ b/gemfiles/rails_4_1.gemfile.lock @@ -0,0 +1,143 @@ +PATH + remote: ../ + specs: + nocms-pages (0.1.0) + awesome_nested_set (>= 3.0.0.rc.6) + globalize (>= 4.0.0, < 5.1) + nocms-blocks (~> 1.1.1) + rails (~> 4.0, >= 4.0.3) + +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.1.13) + actionpack (= 4.1.13) + actionview (= 4.1.13) + mail (~> 2.5, >= 2.5.4) + actionpack (4.1.13) + actionview (= 4.1.13) + activesupport (= 4.1.13) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + actionview (4.1.13) + activesupport (= 4.1.13) + builder (~> 3.1) + erubis (~> 2.7.0) + activemodel (4.1.13) + activesupport (= 4.1.13) + builder (~> 3.1) + activerecord (4.1.13) + activemodel (= 4.1.13) + activesupport (= 4.1.13) + arel (~> 5.0.0) + activesupport (4.1.13) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + appraisal (2.1.0) + bundler + rake + thor (>= 0.14.0) + arel (5.0.1.20140414130214) + awesome_nested_set (3.0.2) + activerecord (>= 4.0.0, < 5) + builder (3.2.2) + capybara (2.5.0) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + carrierwave (0.10.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) + mime-types (>= 1.16) + database_cleaner (1.5.0) + diff-lcs (1.2.5) + erubis (2.7.0) + factory_girl (4.5.0) + activesupport (>= 3.0.0) + faker (1.5.0) + i18n (~> 0.5) + globalize (4.0.3) + activemodel (>= 4.0.0, < 5) + activerecord (>= 4.0.0, < 5) + i18n (0.7.0) + json (1.8.3) + mail (2.6.3) + mime-types (>= 1.16, < 3) + mime-types (2.6.1) + mini_portile (0.6.2) + minitest (5.8.0) + nocms-blocks (1.1.1) + awesome_nested_set (~> 3.0.0) + globalize (>= 4.0.0, < 5.1) + rails (~> 4.0, <= 4.2.3) + nokogiri (1.6.6.2) + mini_portile (~> 0.6.0) + rack (1.5.5) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.1.13) + actionmailer (= 4.1.13) + actionpack (= 4.1.13) + actionview (= 4.1.13) + activemodel (= 4.1.13) + activerecord (= 4.1.13) + activesupport (= 4.1.13) + bundler (>= 1.3.0, < 2.0) + railties (= 4.1.13) + sprockets-rails (~> 2.0) + railties (4.1.13) + actionpack (= 4.1.13) + activesupport (= 4.1.13) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.4.2) + rspec-core (3.0.4) + rspec-support (~> 3.0.0) + rspec-expectations (3.0.4) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.0.0) + rspec-mocks (3.0.4) + rspec-support (~> 3.0.0) + rspec-rails (3.0.2) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-support (~> 3.0.0) + rspec-support (3.0.4) + sprockets (3.3.4) + rack (~> 1.0) + sprockets-rails (2.3.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (>= 2.8, < 4.0) + sqlite3 (1.3.10) + thor (0.19.1) + thread_safe (0.3.5) + tzinfo (1.2.2) + thread_safe (~> 0.1) + xpath (2.0.0) + nokogiri (~> 1.3) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + capybara + carrierwave + database_cleaner + factory_girl + faker + nocms-pages! + rails (= 4.1.13) + rspec-rails (~> 3.0.0.beta) + sqlite3 diff --git a/gemfiles/rails_4_2.gemfile b/gemfiles/rails_4_2.gemfile new file mode 100644 index 0000000..b6f8ae7 --- /dev/null +++ b/gemfiles/rails_4_2.gemfile @@ -0,0 +1,20 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "4.2.3" + +group :development, :test do + gem "faker" + gem "carrierwave" +end + +group :test do + gem "rspec-rails", "~> 3.0.0.beta" + gem "factory_girl" + gem "capybara" + gem "database_cleaner" + gem "appraisal" +end + +gemspec :path => "../" diff --git a/gemfiles/rails_4_2.gemfile.lock b/gemfiles/rails_4_2.gemfile.lock new file mode 100644 index 0000000..1d3e201 --- /dev/null +++ b/gemfiles/rails_4_2.gemfile.lock @@ -0,0 +1,165 @@ +PATH + remote: ../ + specs: + nocms-pages (0.1.0) + awesome_nested_set (>= 3.0.0.rc.6) + globalize (>= 4.0.0, < 5.1) + nocms-blocks (~> 1.1.1) + rails (~> 4.0, >= 4.0.3) + +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.2.3) + actionpack (= 4.2.3) + actionview (= 4.2.3) + activejob (= 4.2.3) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.3) + actionview (= 4.2.3) + activesupport (= 4.2.3) + rack (~> 1.6) + rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.3) + activesupport (= 4.2.3) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.3) + activesupport (= 4.2.3) + globalid (>= 0.3.0) + activemodel (4.2.3) + activesupport (= 4.2.3) + builder (~> 3.1) + activerecord (4.2.3) + activemodel (= 4.2.3) + activesupport (= 4.2.3) + arel (~> 6.0) + activesupport (4.2.3) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + appraisal (2.1.0) + bundler + rake + thor (>= 0.14.0) + arel (6.0.3) + awesome_nested_set (3.0.2) + activerecord (>= 4.0.0, < 5) + builder (3.2.2) + capybara (2.5.0) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + carrierwave (0.10.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) + mime-types (>= 1.16) + database_cleaner (1.5.0) + diff-lcs (1.2.5) + erubis (2.7.0) + factory_girl (4.5.0) + activesupport (>= 3.0.0) + faker (1.5.0) + i18n (~> 0.5) + globalid (0.3.6) + activesupport (>= 4.1.0) + globalize (5.0.1) + activemodel (>= 4.2.0, < 4.3) + activerecord (>= 4.2.0, < 4.3) + i18n (0.7.0) + json (1.8.3) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.3) + mime-types (>= 1.16, < 3) + mime-types (2.6.1) + mini_portile (0.6.2) + minitest (5.8.0) + nocms-blocks (1.1.1) + awesome_nested_set (~> 3.0.0) + globalize (>= 4.0.0, < 5.1) + rails (~> 4.0, <= 4.2.3) + nokogiri (1.6.6.2) + mini_portile (~> 0.6.0) + rack (1.6.4) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.2.3) + actionmailer (= 4.2.3) + actionpack (= 4.2.3) + actionview (= 4.2.3) + activejob (= 4.2.3) + activemodel (= 4.2.3) + activerecord (= 4.2.3) + activesupport (= 4.2.3) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.3) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.7) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.2) + loofah (~> 2.0) + railties (4.2.3) + actionpack (= 4.2.3) + activesupport (= 4.2.3) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.4.2) + rspec-core (3.0.4) + rspec-support (~> 3.0.0) + rspec-expectations (3.0.4) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.0.0) + rspec-mocks (3.0.4) + rspec-support (~> 3.0.0) + rspec-rails (3.0.2) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-support (~> 3.0.0) + rspec-support (3.0.4) + sprockets (3.3.4) + rack (~> 1.0) + sprockets-rails (2.3.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (>= 2.8, < 4.0) + sqlite3 (1.3.10) + thor (0.19.1) + thread_safe (0.3.5) + tzinfo (1.2.2) + thread_safe (~> 0.1) + xpath (2.0.0) + nokogiri (~> 1.3) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + capybara + carrierwave + database_cleaner + factory_girl + faker + nocms-pages! + rails (= 4.2.3) + rspec-rails (~> 3.0.0.beta) + sqlite3 From 74aabbd67891fbe88eabf3702c21ca47f395c584 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Fri, 11 Sep 2015 10:55:00 +0200 Subject: [PATCH 34/37] Adapt test to 4.0, 4.1 and 4.2 rails versions. --- spec/models/nocms/pages/page_spec.rb | 4 +++- spec/spec_helper.rb | 2 +- spec/support/concerns/model_with_required_attributes.rb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/models/nocms/pages/page_spec.rb b/spec/models/nocms/pages/page_spec.rb index 9bd90ac..34dfe5d 100644 --- a/spec/models/nocms/pages/page_spec.rb +++ b/spec/models/nocms/pages/page_spec.rb @@ -61,9 +61,11 @@ let(:page) { create :nocms_page} let(:duplicated_page) { build :nocms_page, slug: page.slug} + before { duplicated_page.valid? } + subject { duplicated_page } - it("should not have a valid path") { expect(subject.errors_on(:path)).to_not be_blank } + it("should not have a valid path") { expect(subject.errors[:path]).to_not be_blank } end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9c906df..0e7d866 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,7 +20,7 @@ config.include FactoryGirl::Syntax::Methods # Capybara DSL only in request specs - config.include Capybara::DSL, :type => :request + config.include Capybara::DSL # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" diff --git a/spec/support/concerns/model_with_required_attributes.rb b/spec/support/concerns/model_with_required_attributes.rb index e89c092..432e786 100644 --- a/spec/support/concerns/model_with_required_attributes.rb +++ b/spec/support/concerns/model_with_required_attributes.rb @@ -12,7 +12,7 @@ subject { model_object } it { should_not be_valid } - it { expect(subject.error_on(attribute_name)).to include I18n.t('errors.messages.blank') } + it { expect(subject.errors[attribute_name]).to include I18n.t('errors.messages.blank') } end end From 3f5ed741c67cd8066a47005a9ff955403a5508b0 Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Fri, 2 Oct 2015 11:18:02 +0200 Subject: [PATCH 35/37] Permit nested attributes on page's translations. --- app/models/no_cms/pages/page.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/no_cms/pages/page.rb b/app/models/no_cms/pages/page.rb index b458422..afa1243 100644 --- a/app/models/no_cms/pages/page.rb +++ b/app/models/no_cms/pages/page.rb @@ -16,6 +16,7 @@ def self.home accepts_nested_attributes_for :blocks, allow_destroy: true translates :title, :body, :slug, :path, :draft, :css_class, :css_id, :cache_enabled + accepts_nested_attributes_for :translations validates :title, presence: true validates :body, presence: true if NoCms::Pages.use_body? From 005e4f613d58d05799a7c16d828e89a835e5557e Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Fri, 2 Oct 2015 11:18:15 +0200 Subject: [PATCH 36/37] Add missing locales. --- config/locales/en.yml | 3 +++ config/locales/es.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index 74db9f9..48f5c37 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -11,6 +11,9 @@ en: css_class: CSS classes css_id: CSS id layout: Layout + parent: Parent + template: Template + draft: Draft no_cms/pages/block: layout: Layout title: Title diff --git a/config/locales/es.yml b/config/locales/es.yml index 126009f..98cbb36 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -11,6 +11,9 @@ es: css_class: Clases CSS css_id: Id CSS layout: Layout + parent: Padre + template: Plantilla + draft: Borrador no_cms/pages/block: layout: Layout title: Título From 1e5d17b3c201b8ccbdc42b3a66ae65f944a869bf Mon Sep 17 00:00:00 2001 From: Luis Mendo Date: Wed, 4 Nov 2015 13:18:50 +0100 Subject: [PATCH 37/37] Update version. --- Gemfile.lock | 2 +- gemfiles/rails_4_0.gemfile.lock | 2 +- gemfiles/rails_4_1.gemfile.lock | 2 +- gemfiles/rails_4_2.gemfile.lock | 2 +- lib/nocms/pages/version.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 534bb5b..68d6ba5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - nocms-pages (0.1.0) + nocms-pages (1.0.0) awesome_nested_set (>= 3.0.0.rc.6) globalize (>= 4.0.0, < 5.1) nocms-blocks (~> 1.1.1) diff --git a/gemfiles/rails_4_0.gemfile.lock b/gemfiles/rails_4_0.gemfile.lock index 9e293cb..c443ea0 100644 --- a/gemfiles/rails_4_0.gemfile.lock +++ b/gemfiles/rails_4_0.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: ../ specs: - nocms-pages (0.1.0) + nocms-pages (1.0.0) awesome_nested_set (>= 3.0.0.rc.6) globalize (>= 4.0.0, < 5.1) nocms-blocks (~> 1.1.1) diff --git a/gemfiles/rails_4_1.gemfile.lock b/gemfiles/rails_4_1.gemfile.lock index 1ad6ab6..def3561 100644 --- a/gemfiles/rails_4_1.gemfile.lock +++ b/gemfiles/rails_4_1.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: ../ specs: - nocms-pages (0.1.0) + nocms-pages (1.0.0) awesome_nested_set (>= 3.0.0.rc.6) globalize (>= 4.0.0, < 5.1) nocms-blocks (~> 1.1.1) diff --git a/gemfiles/rails_4_2.gemfile.lock b/gemfiles/rails_4_2.gemfile.lock index 1d3e201..777c8b6 100644 --- a/gemfiles/rails_4_2.gemfile.lock +++ b/gemfiles/rails_4_2.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: ../ specs: - nocms-pages (0.1.0) + nocms-pages (1.0.0) awesome_nested_set (>= 3.0.0.rc.6) globalize (>= 4.0.0, < 5.1) nocms-blocks (~> 1.1.1) diff --git a/lib/nocms/pages/version.rb b/lib/nocms/pages/version.rb index 28df6bb..89c0d4e 100644 --- a/lib/nocms/pages/version.rb +++ b/lib/nocms/pages/version.rb @@ -1,5 +1,5 @@ module NoCms module Pages - VERSION = "0.1.0" + VERSION = "1.0.0" end end