annex-cms 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/app/assets/javascripts/annex.js +5 -0
  5. data/app/assets/javascripts/annex/cms.js +22 -0
  6. data/app/assets/javascripts/annex/jquery.redactor.clips.js +56 -0
  7. data/app/assets/javascripts/annex/jquery.redactor.fullscreen.js +142 -0
  8. data/app/assets/javascripts/annex/jquery.redactor.js +7308 -0
  9. data/app/assets/javascripts/annex/jquery.redactor.save.js +70 -0
  10. data/app/assets/stylesheets/annex.css.scss +12 -0
  11. data/app/assets/stylesheets/annex/redactor.css.scss +671 -0
  12. data/app/controllers/annex/application_controller.rb +18 -0
  13. data/app/controllers/annex/blocks_controller.rb +28 -0
  14. data/app/controllers/annex/files_controller.rb +12 -0
  15. data/app/models/annex/block.rb +12 -0
  16. data/app/models/annex/file.rb +7 -0
  17. data/app/views/annex/_block.html.haml +2 -0
  18. data/app/views/annex/_clips.html.haml +11 -0
  19. data/config/routes.rb +5 -0
  20. data/lib/annex.rb +8 -0
  21. data/lib/annex/config.rb +87 -0
  22. data/lib/annex/engine.rb +5 -0
  23. data/lib/annex/extension.rb +18 -0
  24. data/lib/annex/extensions/cancan.rb +5 -0
  25. data/lib/annex/extensions/cancan/authorization_adapter.rb +59 -0
  26. data/lib/annex/railtie.rb +9 -0
  27. data/lib/annex/version.rb +3 -0
  28. data/lib/annex/view_helpers.rb +32 -0
  29. data/lib/tasks/annex_tasks.rake +4 -0
  30. data/test/annex_test.rb +7 -0
  31. data/test/controllers/annex/block_controller_test.rb +9 -0
  32. data/test/controllers/annex/blocks_controller_test.rb +51 -0
  33. data/test/dummy/README.rdoc +28 -0
  34. data/test/dummy/Rakefile +6 -0
  35. data/test/dummy/app/assets/javascripts/application.js +13 -0
  36. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  37. data/test/dummy/app/controllers/application_controller.rb +2 -0
  38. data/test/dummy/app/helpers/application_helper.rb +2 -0
  39. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  40. data/test/dummy/bin/bundle +3 -0
  41. data/test/dummy/bin/rails +4 -0
  42. data/test/dummy/bin/rake +4 -0
  43. data/test/dummy/config.ru +4 -0
  44. data/test/dummy/config/application.rb +26 -0
  45. data/test/dummy/config/boot.rb +5 -0
  46. data/test/dummy/config/environment.rb +5 -0
  47. data/test/dummy/config/environments/development.rb +26 -0
  48. data/test/dummy/config/environments/production.rb +80 -0
  49. data/test/dummy/config/environments/test.rb +36 -0
  50. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  51. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  52. data/test/dummy/config/initializers/inflections.rb +16 -0
  53. data/test/dummy/config/initializers/mime_types.rb +5 -0
  54. data/test/dummy/config/initializers/secret_token.rb +12 -0
  55. data/test/dummy/config/initializers/session_store.rb +3 -0
  56. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  57. data/test/dummy/config/locales/en.yml +23 -0
  58. data/test/dummy/config/mongoid.yml +72 -0
  59. data/test/dummy/config/routes.rb +5 -0
  60. data/test/dummy/log/development.log +0 -0
  61. data/test/dummy/public/404.html +58 -0
  62. data/test/dummy/public/422.html +58 -0
  63. data/test/dummy/public/500.html +57 -0
  64. data/test/dummy/public/favicon.ico +0 -0
  65. data/test/fixtures/annex/blocks.yml +9 -0
  66. data/test/helpers/annex/block_helper_test.rb +6 -0
  67. data/test/helpers/annex/blocks_helper_test.rb +6 -0
  68. data/test/integration/navigation_test.rb +10 -0
  69. data/test/models/annex/block_test.rb +9 -0
  70. data/test/test_helper.rb +15 -0
  71. metadata +182 -0
@@ -0,0 +1,18 @@
1
+ module Annex
2
+
3
+ class ApplicationController < ::ApplicationController
4
+ protect_from_forgery with: :null_session
5
+
6
+ before_filter :annex_authenticate!
7
+ before_filter :annex_authorize!
8
+
9
+ def annex_authenticate!
10
+ instance_eval &Annex::Config.authenticate_with
11
+ end
12
+
13
+ def annex_authorize!
14
+ instance_eval &Annex::Config.authorize_with
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,28 @@
1
+ require_dependency "annex/application_controller"
2
+
3
+ module Annex
4
+ class BlocksController < ApplicationController
5
+
6
+ # POST /annex/blocks
7
+ def create
8
+ @block = Block.where(:route => params[:route]).first_or_create
9
+ @block.content ||= {}
10
+
11
+ params[:content].keys.each do |key|
12
+ @block.content[key] = params[:content][key]
13
+ end
14
+
15
+ if @block.save
16
+ render json: {status: :success}, status: :ok
17
+ else
18
+ render json: @block.errors, status: :unprocessable_entity
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def block_params
25
+ params.require(:user).permit(:route, :content)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ require_dependency "annex/application_controller"
2
+
3
+ module Annex
4
+ class FilesController < ApplicationController
5
+
6
+ # POST /annex/documents
7
+ def create
8
+ puts 'create called'
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Annex
2
+ class Block
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ include Mongoid::Attributes::Dynamic
6
+
7
+ field :route, type: String
8
+ field :content, type: Hash
9
+
10
+ validates_presence_of :route
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module Annex
2
+ class File
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ include Mongoid::Attributes::Dynamic
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ .redactor{ { :data => { :identifier => identifier, :route => route } }.deep_merge(opts) }
2
+ = content.html_safe if content
@@ -0,0 +1,11 @@
1
+ #clipsmodal
2
+ %section
3
+ %ul.redactor_clips_box
4
+ %li
5
+ %a.redactor_clip_link{href: "#"} Lorem ipsum …
6
+ .redactor_clip{style: "display: none;"}
7
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
8
+ %li
9
+ = content_for :annex_clip
10
+ %footer
11
+ %a.redactor_modal_btn.redactor_btn_modal_close{href: "#"} Close
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ namespace :annex do
3
+ resources :blocks, :only => [:create], :defaults => { :format => 'json' }
4
+ end
5
+ end
data/lib/annex.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'annex/engine'
2
+ require 'annex/config'
3
+ require 'annex/extension'
4
+ require 'annex/extensions/cancan'
5
+ require 'annex/railtie'
6
+
7
+ module Annex
8
+ end
@@ -0,0 +1,87 @@
1
+ module Annex
2
+ module Config
3
+ # Annex is setup to try and authenticate with warden
4
+ # If warden is found, then it will try to authenticate
5
+ #
6
+ # This is valid for custom warden setups, and also devise
7
+ # If you're using the admin setup for devise, you should set Annex to use the admin
8
+ #
9
+ # @see Annex::Config.authenticate_with
10
+ # @see Annex::Config.authorize_with
11
+ DEFAULT_AUTHENTICATION = Proc.new do
12
+ request.env['warden'].try(:authenticate!)
13
+ end
14
+
15
+ DEFAULT_AUTHORIZE = Proc.new {}
16
+
17
+ DEFAULT_CURRENT_USER = Proc.new do
18
+ request.env["warden"].try(:user) || respond_to?(:current_user) && current_user
19
+ end
20
+
21
+
22
+ class << self
23
+
24
+ # Setup authentication to be run as a before filter
25
+ # This is run inside the controller instance so you can setup any authentication you need to
26
+ #
27
+ # By default, the authentication will run via warden if available
28
+ # and will run the default.
29
+ #
30
+ # If you use devise, this will authenticate the same as _authenticate_user!_
31
+ #
32
+ # @example Devise admin
33
+ # Annex.config do |config|
34
+ # config.authenticate_with do
35
+ # authenticate_admin!
36
+ # end
37
+ # end
38
+ #
39
+ # @example Custom Warden
40
+ # Annex.config do |config|
41
+ # config.authenticate_with do
42
+ # warden.authenticate! :scope => :paranoid
43
+ # end
44
+ # end
45
+ #
46
+ # @see Annex::Config::DEFAULT_AUTHENTICATION
47
+ def authenticate_with(&blk)
48
+ @authenticate = blk if blk
49
+ @authenticate || DEFAULT_AUTHENTICATION
50
+ end
51
+
52
+ # Setup authorization to be run as a before filter
53
+ # This is run inside the controller instance so you can setup any authorization you need to.
54
+ #
55
+ # By default, there is no authorization.
56
+ #
57
+ # @example Custom
58
+ # Annex.config do |config|
59
+ # config.authorize_with do
60
+ # redirect_to root_path unless warden.user.is_admin?
61
+ # end
62
+ # end
63
+ #
64
+ # To use an authorization adapter, pass the name of the adapter. For example,
65
+ # to use with CanCan[https://github.com/ryanb/cancan], pass it like this.
66
+ #
67
+ # @example CanCan
68
+ # Annex.config do |config|
69
+ # config.authorize_with :cancan
70
+ # end
71
+ #
72
+ # @see Annex::Config::DEFAULT_AUTHORIZE
73
+ def authorize_with(*args, &block)
74
+ extension = args.shift
75
+ if(extension)
76
+ @authorize = Proc.new {
77
+ @authorization_adapter = Annex::AUTHORIZATION_ADAPTERS[extension].new(*([self] + args).compact)
78
+ }
79
+ else
80
+ @authorize = block if block
81
+ end
82
+ @authorize || DEFAULT_AUTHORIZE
83
+ end
84
+
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,5 @@
1
+ module Annex
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Annex
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module Annex
2
+ EXTENSIONS = []
3
+ AUTHORIZATION_ADAPTERS = {}
4
+
5
+ # Extend Annex
6
+ #
7
+ # The extension may define various adapters (e.g., for authorization) and
8
+ # register those via the options hash.
9
+ def self.add_extension(extension_key, extension_definition, options = {})
10
+ options.assert_valid_keys(:authorization, :configuration, :auditing)
11
+
12
+ EXTENSIONS << extension_key
13
+
14
+ if(authorization = options[:authorization])
15
+ AUTHORIZATION_ADAPTERS[extension_key] = extension_definition::AuthorizationAdapter
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ require 'annex/extensions/cancan/authorization_adapter'
2
+
3
+ Annex.add_extension(:cancan, Annex::Extensions::CanCan, {
4
+ :authorization => true
5
+ })
@@ -0,0 +1,59 @@
1
+ module Annex
2
+ module Extensions
3
+ module CanCan
4
+ # This adapter is for the CanCan[https://github.com/ryanb/cancan] authorization library.
5
+ # You can create another adapter for different authorization behavior, just be certain it
6
+ # responds to each of the public methods here.
7
+ class AuthorizationAdapter
8
+ # See the +authorize_with+ config method for where the initialization happens.
9
+ def initialize(controller, ability = ::Ability)
10
+ @controller = controller
11
+ @controller.instance_variable_set '@ability', ability
12
+ @controller.extend ControllerExtension
13
+ @controller.current_ability.authorize! :access, :annex
14
+ end
15
+
16
+ # This method is called in every controller action and should raise an exception
17
+ # when the authorization fails. The first argument is the name of the controller
18
+ # action as a symbol (:create, :bulk_delete, etc.). The second argument is the
19
+ # AbstractModel instance that applies. The third argument is the actual model
20
+ # instance if it is available.
21
+ def authorize(action, abstract_model = nil, model_object = nil)
22
+ @controller.current_ability.authorize!(action, model_object || abstract_model && abstract_model.model) if action
23
+ end
24
+
25
+ # This method is called primarily from the view to determine whether the given user
26
+ # has access to perform the action on a given model. It should return true when authorized.
27
+ # This takes the same arguments as +authorize+. The difference is that this will
28
+ # return a boolean whereas +authorize+ will raise an exception when not authorized.
29
+ def authorized?(action, abstract_model = nil, model_object = nil)
30
+ @controller.current_ability.can?(action, model_object || abstract_model && abstract_model.model) if action
31
+ end
32
+
33
+ # This is called when needing to scope a database query. It is called within the list
34
+ # and bulk_delete/destroy actions and should return a scope which limits the records
35
+ # to those which the user can perform the given action on.
36
+ def query(action, abstract_model)
37
+ abstract_model.model.accessible_by(@controller.current_ability, action)
38
+ end
39
+
40
+ # This is called in the new/create actions to determine the initial attributes for new
41
+ # records. It should return a hash of attributes which match what the user
42
+ # is authorized to create.
43
+ def attributes_for(action, abstract_model)
44
+ @controller.current_ability.attributes_for(action, abstract_model && abstract_model.model)
45
+ end
46
+
47
+ private
48
+
49
+ module ControllerExtension
50
+ def current_ability
51
+ # use _current_user instead of default current_user so it works with
52
+ # whatever current user method is defined with Annex
53
+ @current_ability ||= @ability.new(_current_user)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,9 @@
1
+ require 'annex/view_helpers'
2
+
3
+ module Annex
4
+ class Railtie < Rails::Railtie
5
+ initializer "annex.view_helpers" do
6
+ ActionView::Base.send :include, ViewHelpers
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Annex
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'active_support/hash_with_indifferent_access'
2
+
3
+ module Annex
4
+ module ViewHelpers
5
+ def annex_block(identifier, opts = {})
6
+ if opts.try(:route)
7
+ route = opts[:route]
8
+ opts[:route].delete
9
+ else
10
+ route = current_route
11
+ end
12
+
13
+ doc = Annex::Block.where(:route => route.to_s).first_or_create
14
+
15
+ if doc.content
16
+ content = doc.content[identifier.to_s] || ''
17
+ else
18
+ content = ''
19
+ end
20
+
21
+ render partial: 'annex/block', locals: { content: content, route: route, identifier: identifier, opts: opts }
22
+ end
23
+
24
+ def annex_clips(clip)
25
+ render partial: 'annex/clips'
26
+ end
27
+
28
+ def current_route
29
+ "#{I18n.locale}_#{params[:controller]}_#{params[:action]}".to_sym
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :annex do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class AnnexTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, Annex
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module Annex
4
+ class BlockControllerTest < ActionController::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ module Annex
4
+ class BlocksControllerTest < ActionController::TestCase
5
+ setup do
6
+ @block = blocks(:one)
7
+ end
8
+
9
+ test "should get index" do
10
+ get :index
11
+ assert_response :success
12
+ assert_not_nil assigns(:blocks)
13
+ end
14
+
15
+ test "should get new" do
16
+ get :new
17
+ assert_response :success
18
+ end
19
+
20
+ test "should create block" do
21
+ assert_difference('Block.count') do
22
+ post :create, block: { content: @block.content, route: @block.route }
23
+ end
24
+
25
+ assert_redirected_to block_path(assigns(:block))
26
+ end
27
+
28
+ test "should show block" do
29
+ get :show, id: @block
30
+ assert_response :success
31
+ end
32
+
33
+ test "should get edit" do
34
+ get :edit, id: @block
35
+ assert_response :success
36
+ end
37
+
38
+ test "should update block" do
39
+ patch :update, id: @block, block: { content: @block.content, route: @block.route }
40
+ assert_redirected_to block_path(assigns(:block))
41
+ end
42
+
43
+ test "should destroy block" do
44
+ assert_difference('Block.count', -1) do
45
+ delete :destroy, id: @block
46
+ end
47
+
48
+ assert_redirected_to blocks_path
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.