cmsimple 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +31 -0
- data/.rspec +1 -0
- data/.travis.yml +16 -0
- data/Gemfile +20 -0
- data/Gemfile.ci +5 -0
- data/LICENSE +19 -0
- data/README.md +118 -0
- data/Rakefile +47 -0
- data/app/assets/javascripts/cmsimple.js +61 -0
- data/app/assets/javascripts/cmsimple/controllers/editor.coffee +102 -0
- data/app/assets/javascripts/cmsimple/lib/namespaces.coffee +3 -0
- data/app/assets/javascripts/cmsimple/lib/support.coffee +4 -0
- data/app/assets/javascripts/cmsimple/mercury/config.js +462 -0
- data/app/assets/javascripts/cmsimple/mercury/handlers.coffee +9 -0
- data/app/assets/javascripts/cmsimple/models/image.coffee +49 -0
- data/app/assets/javascripts/cmsimple/models/page.coffee +106 -0
- data/app/assets/javascripts/cmsimple/models/path.coffee +31 -0
- data/app/assets/javascripts/cmsimple/models/version.coffee +29 -0
- data/app/assets/javascripts/cmsimple/panels/images/index.coffee +2 -0
- data/app/assets/javascripts/cmsimple/panels/images/list.coffee +48 -0
- data/app/assets/javascripts/cmsimple/panels/images/panel.coffee +69 -0
- data/app/assets/javascripts/cmsimple/panels/images/selection.coffee +52 -0
- data/app/assets/javascripts/cmsimple/panels/page_metadata.coffee +42 -0
- data/app/assets/javascripts/cmsimple/panels/publish.coffee +32 -0
- data/app/assets/javascripts/cmsimple/panels/redirects/form.coffee +51 -0
- data/app/assets/javascripts/cmsimple/panels/redirects/index.coffee +2 -0
- data/app/assets/javascripts/cmsimple/panels/redirects/list.coffee +34 -0
- data/app/assets/javascripts/cmsimple/panels/redirects/panel.coffee +39 -0
- data/app/assets/javascripts/cmsimple/panels/sitemap/index.coffee +2 -0
- data/app/assets/javascripts/cmsimple/panels/sitemap/panel.coffee +40 -0
- data/app/assets/javascripts/cmsimple/panels/sitemap/sortable.coffee +55 -0
- data/app/assets/javascripts/cmsimple/panels/sitemap/tree.coffee +61 -0
- data/app/assets/javascripts/cmsimple/panels/versions/index.coffee +2 -0
- data/app/assets/javascripts/cmsimple/panels/versions/list.coffee +51 -0
- data/app/assets/javascripts/cmsimple/panels/versions/panel.coffee +53 -0
- data/app/assets/javascripts/cmsimple/views/image_library/_item.jst.hamlc +24 -0
- data/app/assets/javascripts/cmsimple/views/image_library/list.jst.hamlc +8 -0
- data/app/assets/javascripts/cmsimple/views/redirects/_path.jst.hamlc +6 -0
- data/app/assets/javascripts/cmsimple/views/redirects/list.jst.hamlc +19 -0
- data/app/assets/javascripts/cmsimple/views/sitemap/_page.jst.hamlc +9 -0
- data/app/assets/javascripts/cmsimple/views/sitemap/tree.jst.hamlc +5 -0
- data/app/assets/javascripts/cmsimple/views/versions/_item.jst.hamlc +6 -0
- data/app/assets/javascripts/cmsimple/views/versions/list.jst.hamlc +4 -0
- data/app/assets/stylesheets/cmsimple.css +15 -0
- data/app/assets/stylesheets/cmsimple/forms.css +10 -0
- data/app/assets/stylesheets/cmsimple/panels.css +399 -0
- data/app/assets/stylesheets/cmsimple/toolbar-images.css +27 -0
- data/app/assets/stylesheets/mercury_overrides.css +2 -0
- data/app/controllers/cmsimple/front_controller.rb +38 -0
- data/app/controllers/cmsimple/images_controller.rb +28 -0
- data/app/controllers/cmsimple/mercury_controller.rb +7 -0
- data/app/controllers/cmsimple/pages_controller.rb +89 -0
- data/app/controllers/cmsimple/paths_controller.rb +23 -0
- data/app/controllers/cmsimple/snippets_controller.rb +23 -0
- data/app/controllers/cmsimple/versions_controller.rb +17 -0
- data/app/helpers/cmsimple/regions_helper.rb +38 -0
- data/app/models/cmsimple/image.rb +19 -0
- data/app/models/cmsimple/page.rb +203 -0
- data/app/models/cmsimple/path.rb +63 -0
- data/app/models/cmsimple/region.rb +43 -0
- data/app/models/cmsimple/snippet.rb +64 -0
- data/app/models/cmsimple/version.rb +18 -0
- data/app/uploaders/image_attachment_uploader.rb +53 -0
- data/app/views/cmsimple/images/_form.html.haml +13 -0
- data/app/views/cmsimple/images/new.html.haml +5 -0
- data/app/views/cmsimple/pages/_form.html.haml +49 -0
- data/app/views/cmsimple/pages/_form_extras.html.haml +2 -0
- data/app/views/cmsimple/pages/edit.html.haml +3 -0
- data/app/views/cmsimple/pages/new.html.haml +3 -0
- data/app/views/cmsimple/pages/publish.html.haml +12 -0
- data/app/views/cmsimple/snippets/index.html.haml +5 -0
- data/app/views/cmsimple/templates/default.html.haml +4 -0
- data/app/views/layouts/editor.html.haml +12 -0
- data/app/views/layouts/panel.html.haml +9 -0
- data/cmsimple.gemspec +44 -0
- data/config.ru +4 -0
- data/config/application.rb +1 -0
- data/config/cucumber.yml +8 -0
- data/config/environment.rb +2 -0
- data/config/routes.rb +34 -0
- data/db/migrate/20120201221410_create_cmsimple_pages.rb +10 -0
- data/db/migrate/20120222185901_add_title_parent_id_and_position_to_pages.rb +10 -0
- data/db/migrate/20120229185214_add_slug_to_pages.rb +7 -0
- data/db/migrate/20120323200439_add_is_root_to_page.rb +5 -0
- data/db/migrate/20120328174339_add_meta_info_to_cmsimple_pages.rb +9 -0
- data/db/migrate/20120329172857_create_cmsimple_path.rb +11 -0
- data/db/migrate/20120407024752_create_cmsimple_images.rb +13 -0
- data/db/migrate/20120410041105_add_timestamps_to_cmsimple_pages.rb +7 -0
- data/db/migrate/20120425211937_add_published_at_to_cmsimple_pages.rb +6 -0
- data/db/migrate/20120430175047_create_cmsimple_versions.rb +13 -0
- data/db/migrate/20120831233927_rename_path_to_current_uri_on_paths.rb +5 -0
- data/features/create.feature +18 -0
- data/features/delete.feature +12 -0
- data/features/edit.feature +54 -0
- data/features/publishing.feature +31 -0
- data/features/redirects.feature +27 -0
- data/features/step_definitions/mercury_steps.rb +440 -0
- data/features/step_definitions/page_steps.rb +269 -0
- data/features/step_definitions/web_steps.rb +254 -0
- data/features/support/env.rb +77 -0
- data/features/support/mercury_content.rb +25 -0
- data/features/support/mercury_selectors.rb +148 -0
- data/features/support/paths.rb +16 -0
- data/features/support/selectors.rb +26 -0
- data/features/support/utils.rb +18 -0
- data/features/versioning.feature +27 -0
- data/features/visit.feature +7 -0
- data/lib/cmsimple.rb +22 -0
- data/lib/cmsimple/configuration.rb +65 -0
- data/lib/cmsimple/exts/to_bool.rb +25 -0
- data/lib/cmsimple/page_responder.rb +46 -0
- data/lib/cmsimple/rails.rb +5 -0
- data/lib/cmsimple/regions_proxy.rb +32 -0
- data/lib/cmsimple/template_resolver.rb +14 -0
- data/lib/cmsimple/template_responder.rb +12 -0
- data/lib/cmsimple/version.rb +3 -0
- data/lib/generators/cmsimple/install/install_generator.rb +46 -0
- data/lib/generators/cmsimple/install/templates/default.html.erb +10 -0
- data/lib/generators/cmsimple/install/templates/default.html.haml +6 -0
- data/lib/generators/cmsimple/install/templates/initializer.rb +22 -0
- data/lib/generators/cmsimple/snippet/snippet_generator.rb +56 -0
- data/lib/generators/cmsimple/snippet/templates/cell.rb +18 -0
- data/lib/generators/cmsimple/snippet/templates/display.html.erb +14 -0
- data/lib/generators/cmsimple/snippet/templates/display.html.haml +11 -0
- data/lib/generators/cmsimple/snippet/templates/options.html.erb +18 -0
- data/lib/generators/cmsimple/snippet/templates/options.html.haml +12 -0
- data/script/app +2 -0
- data/script/migrate +2 -0
- data/script/rails +8 -0
- data/spec/fixtures/rails.png +0 -0
- data/spec/helpers/regions_helper_spec.rb +62 -0
- data/spec/javascripts/controllers/editor_spec.coffee +57 -0
- data/spec/javascripts/models/image_geometry_spec.coffee +64 -0
- data/spec/javascripts/models/image_spec.coffee +4 -0
- data/spec/javascripts/models/page_spec.coffee +121 -0
- data/spec/javascripts/models/path_spec.coffee +39 -0
- data/spec/javascripts/models/version_spec.coffee +31 -0
- data/spec/javascripts/panels/images/selection_spec.coffee +104 -0
- data/spec/javascripts/panels/sitemap/panel_spec.coffee +10 -0
- data/spec/javascripts/panels/sitemap/sortable_spec.coffee +63 -0
- data/spec/javascripts/panels/sitemap/tree_spec.coffee +62 -0
- data/spec/javascripts/spec_helper.coffee +25 -0
- data/spec/javascripts/support/stubs.coffee +16 -0
- data/spec/lib/page_responder_spec.rb +58 -0
- data/spec/lib/regions_proxy_spec.rb +47 -0
- data/spec/models/image_spec.rb +46 -0
- data/spec/models/page_spec.rb +237 -0
- data/spec/models/path_spec.rb +71 -0
- data/spec/models/region_spec.rb +14 -0
- data/spec/models/snippet_spec.rb +57 -0
- data/spec/models/version_spec.rb +7 -0
- data/spec/rails_app/.gitignore +33 -0
- data/spec/rails_app/Rakefile +7 -0
- data/spec/rails_app/app/assets/images/rails.png +0 -0
- data/spec/rails_app/app/assets/javascripts/application.js +9 -0
- data/spec/rails_app/app/assets/stylesheets/application.css +7 -0
- data/spec/rails_app/app/cells/example/display.html.haml +2 -0
- data/spec/rails_app/app/cells/example/options.html.haml +15 -0
- data/spec/rails_app/app/cells/example_cell.rb +19 -0
- data/spec/rails_app/app/cells/image_example/display.html.haml +4 -0
- data/spec/rails_app/app/cells/image_example/options.html.haml +15 -0
- data/spec/rails_app/app/cells/image_example_cell.rb +18 -0
- data/spec/rails_app/app/controllers/application_controller.rb +3 -0
- data/spec/rails_app/app/helpers/application_helper.rb +2 -0
- data/spec/rails_app/app/mailers/.gitkeep +0 -0
- data/spec/rails_app/app/models/.gitkeep +0 -0
- data/spec/rails_app/app/views/cmsimple/_snippet_list.html.haml +8 -0
- data/spec/rails_app/app/views/cmsimple/templates/default.html.haml +19 -0
- data/spec/rails_app/app/views/cmsimple/templates/test.html.haml +2 -0
- data/spec/rails_app/app/views/layouts/application.html.haml +13 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/config/application.rb +65 -0
- data/spec/rails_app/config/boot.rb +9 -0
- data/spec/rails_app/config/database.example.yml +22 -0
- data/spec/rails_app/config/database.travis.yml +8 -0
- data/spec/rails_app/config/environment.rb +5 -0
- data/spec/rails_app/config/environments/development.rb +30 -0
- data/spec/rails_app/config/environments/test.rb +39 -0
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_app/config/initializers/cells.rb +1 -0
- data/spec/rails_app/config/initializers/cmsimple.rb +3 -0
- data/spec/rails_app/config/initializers/inflections.rb +10 -0
- data/spec/rails_app/config/initializers/mime_types.rb +5 -0
- data/spec/rails_app/config/initializers/secret_token.rb +7 -0
- data/spec/rails_app/config/initializers/session_store.rb +8 -0
- data/spec/rails_app/config/initializers/teabag.rb +58 -0
- data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails_app/config/locales/en.yml +5 -0
- data/spec/rails_app/config/routes.rb +61 -0
- data/spec/rails_app/db/seeds.rb +11 -0
- data/spec/rails_app/lib/assets/.gitkeep +0 -0
- data/spec/rails_app/lib/tasks/.gitkeep +0 -0
- data/spec/rails_app/public/404.html +26 -0
- data/spec/rails_app/public/422.html +26 -0
- data/spec/rails_app/public/500.html +26 -0
- data/spec/rails_app/public/robots.txt +5 -0
- data/spec/rails_app/script/rails +6 -0
- data/spec/rails_app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/rails_app/vendor/plugins/.gitkeep +0 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/active_model_lint_example.rb +14 -0
- data/spec/teabag_env.rb +28 -0
- data/vendor/assets/images/sitemap/has-changes.png +0 -0
- data/vendor/assets/images/sitemap/published.png +0 -0
- data/vendor/assets/images/sitemap/unpublished.png +0 -0
- data/vendor/assets/images/toolbar/metadata.png +0 -0
- data/vendor/assets/images/toolbar/publish.png +0 -0
- data/vendor/assets/images/toolbar/redirect.png +0 -0
- data/vendor/assets/images/toolbar/sitemap.png +0 -0
- data/vendor/assets/images/toolbar/snippets.png +0 -0
- data/vendor/assets/images/toolbar/unpublished.png +0 -0
- data/vendor/assets/images/tree-line-horizontal-last.png +0 -0
- data/vendor/assets/images/tree-line-horizontal.png +0 -0
- data/vendor/assets/images/tree-line-vertical.png +0 -0
- data/vendor/assets/javascripts/jquery-serializeObject.js +107 -0
- data/vendor/assets/javascripts/jquery.to-json.js +74 -0
- data/vendor/assets/javascripts/jquery.ui.nestedSortable-1.3.4.js +391 -0
- data/vendor/assets/javascripts/moment-1.6.2.js +918 -0
- data/vendor/assets/javascripts/underscore-1.3.1.js +31 -0
- data/vendor/assets/stylesheets/jasmine-modified.css +216 -0
- metadata +686 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
module Cmsimple
|
2
|
+
class PageResponder
|
3
|
+
def initialize(controller)
|
4
|
+
@controller = controller
|
5
|
+
@request = @controller.request
|
6
|
+
@params = @request.params
|
7
|
+
@page = @controller.current_page
|
8
|
+
end
|
9
|
+
|
10
|
+
def respond
|
11
|
+
@controller.respond_with page_for_context
|
12
|
+
end
|
13
|
+
|
14
|
+
def page_for_context
|
15
|
+
raise ActiveRecord::RecordNotFound unless current_page_is_viewable?
|
16
|
+
|
17
|
+
return published_context? ||
|
18
|
+
version_context? ||
|
19
|
+
draft_context?
|
20
|
+
end
|
21
|
+
|
22
|
+
def published_context?
|
23
|
+
unless is_currently_editable?
|
24
|
+
return @page if @page.as_published!
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def version_context?
|
29
|
+
if @params[:version].present?
|
30
|
+
return @page if @page.at_version!(@params[:version])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def draft_context?
|
35
|
+
@page
|
36
|
+
end
|
37
|
+
|
38
|
+
def current_page_is_viewable?
|
39
|
+
is_currently_editable? || @page.published?
|
40
|
+
end
|
41
|
+
|
42
|
+
def is_currently_editable?
|
43
|
+
@controller.in_editor_iframe?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Cmsimple
|
2
|
+
class RegionsProxy
|
3
|
+
attr_accessor :regions_hash
|
4
|
+
|
5
|
+
def initialize(regions_hash)
|
6
|
+
if regions_hash.is_a?(Hash)
|
7
|
+
@regions_hash = ActiveSupport::HashWithIndifferentAccess.new(regions_hash.dup)
|
8
|
+
define_regions
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def snippets_hash
|
13
|
+
return {} unless @regions_hash.present?
|
14
|
+
@regions_hash.inject(ActiveSupport::HashWithIndifferentAccess.new){|h, (k,v)| h.merge(v[:snippets].presence || {})}
|
15
|
+
end
|
16
|
+
|
17
|
+
def define_regions
|
18
|
+
mod = Module.new
|
19
|
+
extend mod
|
20
|
+
|
21
|
+
region_methods = @regions_hash.collect do |key, value|
|
22
|
+
%{def #{key}() Cmsimple::Region.new(@regions_hash[:#{key}]); end}
|
23
|
+
end
|
24
|
+
|
25
|
+
mod.module_eval region_methods.join("\n"), __FILE__, __LINE__ + 1
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing method, *args, &block
|
29
|
+
Region.new {}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Cmsimple
|
2
|
+
class TemplateResolver
|
3
|
+
def self.all
|
4
|
+
templates = []
|
5
|
+
ActionController::Base.view_paths.each do |path|
|
6
|
+
template_directory = File.join(path, Cmsimple.configuration.template_path)
|
7
|
+
Dir[File.join(template_directory, "*.*")].each do |file|
|
8
|
+
templates << File.basename(file).split('.').first
|
9
|
+
end
|
10
|
+
end
|
11
|
+
templates.uniq
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Cmsimple
|
2
|
+
class TemplateResponder < ActionController::Responder
|
3
|
+
def default_render
|
4
|
+
if controller.action_name == 'show'
|
5
|
+
template = File.join Cmsimple.configuration.template_path, (@resource.template.presence || 'default')
|
6
|
+
controller.render template, @resource.template_render_options
|
7
|
+
else
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
class Cmsimple::InstallGenerator < Rails::Generators::Base
|
4
|
+
class_option :template_engine
|
5
|
+
class_option :test_framework
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
def create_initializer
|
9
|
+
template 'initializer.rb', 'config/initializers/cmsimple.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_routes
|
13
|
+
route %Q{#this route should always be last
|
14
|
+
mount Cmsimple::Engine => '/'}
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_default_template
|
18
|
+
file = "default.html.#{handler}"
|
19
|
+
template file, "app/views/cmsimple/templates/#{file}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_snippets_list
|
23
|
+
create_file "app/views/cmsimple/_snippet_list.html.#{handler}", "Run the snippet generator to add a snippet"
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_to_seeds_file
|
27
|
+
seed = <<-SEED
|
28
|
+
unless Cmsimple::Page.where(is_root: true).first
|
29
|
+
page = Cmsimple::Page.create is_root: true, title: 'Home', template: 'default'
|
30
|
+
page.publish!
|
31
|
+
end
|
32
|
+
SEED
|
33
|
+
append_to_file 'db/seeds.rb', seed
|
34
|
+
end
|
35
|
+
|
36
|
+
def install_migrations
|
37
|
+
rake('cmsimple:install:migrations')
|
38
|
+
rake('db:migrate')
|
39
|
+
rake('db:seed')
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def handler
|
44
|
+
options[:template_engine]
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Cmsimple.configure do |cmsimple|
|
2
|
+
#the parent controller for all the page CRUD activities
|
3
|
+
# cmsimple.parent_controller = 'ApplicationController'
|
4
|
+
|
5
|
+
# the parent controller for the page rendering
|
6
|
+
# cmsimple.parent_front_controller = 'ApplicationController'
|
7
|
+
|
8
|
+
# the path the templates are loaded from
|
9
|
+
# cmsimple.template_path = 'cmsimple/templates'
|
10
|
+
|
11
|
+
# the path carrierwave will use to store image assets
|
12
|
+
# self.asset_path = 'uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}'
|
13
|
+
|
14
|
+
# stylesheets to be included in the editor layout page
|
15
|
+
# self.editor_stylesheets << 'cmsimple_overrides'
|
16
|
+
|
17
|
+
# javascripts to be included in the editor layout page
|
18
|
+
# self.editor_javascripts << 'cmsimple_overrides'
|
19
|
+
|
20
|
+
# set this to change layouts or pass other params into rendering a template
|
21
|
+
# self.template_render_options = {}
|
22
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/named_base'
|
3
|
+
|
4
|
+
class Cmsimple::SnippetGenerator < Rails::Generators::NamedBase
|
5
|
+
class_option :template_engine
|
6
|
+
class_option :test_framework
|
7
|
+
class_option :base_snippet_class, :type => :string, :default => "Cell::Rails"
|
8
|
+
argument :fields, :type => :array, :default => [:name], :banner => "field field"
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
10
|
+
|
11
|
+
def create_cell_file
|
12
|
+
template 'cell.rb', "#{base_path}_cell.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_view_files
|
16
|
+
file = "display.html.#{handler}"
|
17
|
+
@path = File.join(base_path, file)
|
18
|
+
template file, @path
|
19
|
+
|
20
|
+
@fields = fields
|
21
|
+
file = "options.html.#{handler}"
|
22
|
+
@path = File.join(base_path, file)
|
23
|
+
template file, @path
|
24
|
+
end
|
25
|
+
|
26
|
+
# this is gross need to write something that acts like template but just returns the result
|
27
|
+
def add_to_snippet_list
|
28
|
+
html = ''
|
29
|
+
if handler.to_sym == :haml
|
30
|
+
html = <<-HTML
|
31
|
+
%li(data-filter="#{class_name.underscore}, snippet, name")
|
32
|
+
%img(alt="#{class_name.humanize} Snippet" data-snippet="#{class_name.underscore}" src="/assets/toolbar/snippets.png")
|
33
|
+
%h4>#{class_name.humanize}
|
34
|
+
.description A one or two line long description of what this snippet does.
|
35
|
+
HTML
|
36
|
+
elsif handler.to_sym == :erb
|
37
|
+
html = <<-HTML
|
38
|
+
<li data-filter="#{class_name.underscore}, snippet, name">
|
39
|
+
<img alt="#{class_name.humanize} Snippet" data-snippet="#{class_name.underscore}" src="/assets/toolbar/snippets.png">
|
40
|
+
<h4>#{class_name.humanize}</h4>
|
41
|
+
<div class="description"> A one or two line long description of what this snippet does.</div>
|
42
|
+
</li>
|
43
|
+
HTML
|
44
|
+
end
|
45
|
+
append_to_file "app/views/cmsimple/_snippet_list.html.#{handler}", html
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def base_path
|
50
|
+
File.join('app/cells', class_path, file_name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def handler
|
54
|
+
options[:template_engine]
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class <%= class_name %>Cell < <%= options.base_snippet_class %>
|
2
|
+
|
3
|
+
def display(snippet)
|
4
|
+
<%- @fields.each do |field| -%>
|
5
|
+
@<%= field %> = snippet.<%= field %>
|
6
|
+
<%- end -%>
|
7
|
+
render view: :display
|
8
|
+
end
|
9
|
+
|
10
|
+
def preview(snippet)
|
11
|
+
display(snippet)
|
12
|
+
end
|
13
|
+
|
14
|
+
def options(snippet)
|
15
|
+
@snippet = snippet
|
16
|
+
render
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<div class="mercury-display-pane" style='width: 500px'>
|
2
|
+
<%%= form_for @snippet, :url => '#', html: { class: 'form-horizontal' } do |f| %>
|
3
|
+
<fieldset>
|
4
|
+
<legend><%= class_name %> Snippet</legend>
|
5
|
+
<%- @fields.each do |field| -%>
|
6
|
+
<div class="control-group">
|
7
|
+
<%%= f.label :<%= field %>, class: 'control-label' %>
|
8
|
+
<div class="controls">
|
9
|
+
<%%= f.input :<%= field %> %>
|
10
|
+
</div>
|
11
|
+
</div>
|
12
|
+
<%- end -%>
|
13
|
+
</fieldset>
|
14
|
+
<div class="form-actions mercury-display-controls">
|
15
|
+
<%%= f.submit class: 'btn btn=primary' %>
|
16
|
+
</div>
|
17
|
+
<%% end %>
|
18
|
+
</div>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
.mercury-display-pane(style='width: 500px')
|
2
|
+
= form_for @snippet, :url => '#', html: { class: 'form-horizontal'} do |f|
|
3
|
+
%fieldset
|
4
|
+
%legend <%= class_name %> Snippet
|
5
|
+
<%- @fields.each do |field| -%>
|
6
|
+
.control-group
|
7
|
+
= f.label :<%= field %>, class: 'control-label'
|
8
|
+
.controls
|
9
|
+
= f.text_field :<%= field %>
|
10
|
+
<%- end -%>
|
11
|
+
.form-actions.mercury-display-controls
|
12
|
+
= f.submit class: 'btn btn-primary'
|
data/script/app
ADDED
data/script/migrate
ADDED
data/script/rails
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/cmsimple/rails', __FILE__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'rails/engine/commands'
|
Binary file
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cell/test_case'
|
3
|
+
describe Cmsimple::RegionsHelper do
|
4
|
+
include Cell::TestCase::TestMethods
|
5
|
+
|
6
|
+
it 'returns the value of the region' do
|
7
|
+
region_content(Cmsimple::Region.new value: '<h1>blah</h1>').should == '<h1>blah</h1>'
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'rendering a region' do
|
11
|
+
before do
|
12
|
+
@region = Cmsimple::Region.new(value: "<div>some content</div><div>[snippet_0/0]</div>",
|
13
|
+
snippets: {snippet_0: {name: 'example',
|
14
|
+
options: { first_name: 'Fred',
|
15
|
+
last_name: 'Flinstone'
|
16
|
+
}}})
|
17
|
+
@page = mock('page', :regions => mock('regions', :body => @region, :heading => Cmsimple::Region.new({})))
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'renders without a wrapper tag if no tag provided' do
|
21
|
+
content = render_region(:body)
|
22
|
+
content.should have_selector('h1', content: 'Fred Flinstone')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'renders block if region has no content' do
|
26
|
+
content = render_region(:heading) do
|
27
|
+
'blah'
|
28
|
+
end
|
29
|
+
content.should == 'blah'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'renders the region with a wrapper if a tag is specified' do
|
33
|
+
content = render_region(:body, tag: :section)
|
34
|
+
content.should have_selector('h1', content: 'Fred Flinstone')
|
35
|
+
content.should have_selector("section[data-mercury='full']")
|
36
|
+
content.should have_selector('section#body')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'renders the region with a wrapper and set class and region type from options' do
|
40
|
+
content = render_region(:body, tag: :section, html: {class: 'blah'}, region_type: 'snippets')
|
41
|
+
content.should have_selector('h1', content: 'Fred Flinstone')
|
42
|
+
content.should have_selector('section.blah')
|
43
|
+
content.should have_selector("section[data-mercury='snippets']")
|
44
|
+
content.should have_selector('section#body')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'snippets' do
|
49
|
+
before do
|
50
|
+
@region = Cmsimple::Region.new(value: "<div>some content</div><div>[snippet_0/0]</div>",
|
51
|
+
snippets: {snippet_0: {name: 'example',
|
52
|
+
options: { first_name: 'Fred',
|
53
|
+
last_name: 'Flinstone'
|
54
|
+
}}})
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'renders the snippets when present' do
|
58
|
+
rendered_region = region_content(@region)
|
59
|
+
rendered_region.should have_selector('h1', content: 'Fred Flinstone')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#= require cmsimple
|
2
|
+
|
3
|
+
describe 'CMSimple.Editor', ->
|
4
|
+
beforeEach ->
|
5
|
+
@page = new CMSimple.Page slug: 'about'
|
6
|
+
spyOn(CMSimple.Editor::, 'initializeMercury')
|
7
|
+
@editor = new CMSimple.Editor @page
|
8
|
+
@editor.mercury =
|
9
|
+
iframe:
|
10
|
+
data: (->)
|
11
|
+
loadIframeSrc: ((path)-> @path = path)
|
12
|
+
|
13
|
+
describe 'initialization', ->
|
14
|
+
|
15
|
+
it 'calls loadMercury', ->
|
16
|
+
expect(CMSimple.Editor::initializeMercury).toHaveBeenCalled()
|
17
|
+
|
18
|
+
it 'sets CMSimple.Editor.current_page to the page passed to the constructor', ->
|
19
|
+
expect(CMSimple.Editor.current_page).toEqual(@page)
|
20
|
+
expect(@editor.current_page).toEqual(@page)
|
21
|
+
|
22
|
+
describe 'reloading with page changes', ->
|
23
|
+
|
24
|
+
it 'returns true when the path argument does not match the window.location', ->
|
25
|
+
spyOn(String::, 'match').andCallFake(-> ['http://cmsimple.dev/editor/about_us', '/editor/about_us'])
|
26
|
+
expect(@editor.pathChange('/editor/contact_us')).toEqual(true)
|
27
|
+
|
28
|
+
it 'calls navigate if the path does not match the current page path on a reload call', ->
|
29
|
+
spyOn(String::, 'match').andCallFake(-> ['http://cmsimple.dev/editor/about_us', '/editor/about_us'])
|
30
|
+
spyOn(@editor, 'navigate')
|
31
|
+
@editor.reload()
|
32
|
+
expect(@editor.navigate).toHaveBeenCalled()
|
33
|
+
|
34
|
+
it 'calls loadPath if the path does match the current page path on a reload call', ->
|
35
|
+
spyOn(String::, 'match').andCallFake(-> ['http://cmsimple.dev/editor/about', '/editor/about'])
|
36
|
+
spyOn(@editor, 'loadPath')
|
37
|
+
@editor.reload()
|
38
|
+
expect(@editor.loadPath).toHaveBeenCalled()
|
39
|
+
|
40
|
+
describe 'loading a new page', ->
|
41
|
+
beforeEach ->
|
42
|
+
@otherPage = new CMSimple.Page slug: 'contact'
|
43
|
+
@otherPage.save ajax: false
|
44
|
+
spyOn(Mercury.Snippet, 'clearAll').andCallThrough()
|
45
|
+
spyOn(Mercury.Snippet, 'load')
|
46
|
+
@editor.loadNewPageFromPath('/contact')
|
47
|
+
|
48
|
+
it 'sets the current page to the page with the matching path', ->
|
49
|
+
expect(@editor.current_page).toEqual(@otherPage)
|
50
|
+
|
51
|
+
it 'reloads the snippets', ->
|
52
|
+
expect(Mercury.Snippet.clearAll).toHaveBeenCalled()
|
53
|
+
expect(Mercury.Snippet.load).toHaveBeenCalled()
|
54
|
+
|
55
|
+
it 'loads the new path in mercury', ->
|
56
|
+
expect(@editor.mercury.path).toEqual(@otherPage.path())
|
57
|
+
|