annex-cms 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 024ade0ac1caccb177d71048c7172c81725644bb
4
- data.tar.gz: 7743d1248bc142405b35c4d590567d3509ccedf5
3
+ metadata.gz: f422eaac34d49d4e56c7cb94467ef9ecd143784c
4
+ data.tar.gz: d20e1e5c2f759333f59c94bc1506aa28214cadc5
5
5
  SHA512:
6
- metadata.gz: e62aa93d19fc243e9caece0c4fa7821566cd79978f98127cd80e3a74ee7fd504fd8e18c6261dd39befed0a07745bfd7d7f320bc05c276b0606daaf9e5205371e
7
- data.tar.gz: 45e7f037e099d03553f2b4abd9489af45b79d2e3080f2a3cd43f6a4101ad0f7864567f2474b89b64e386bbd6c38ff01ec328a6e7083c31ee8bd30d8d66e058ad
6
+ metadata.gz: 92308f85a5a19d46a0ce54f666caa1bdd0f7411d70aa210452ac8f1a8f00ca2707f99885efa49f66a18db5211c0f11555c0b533b9aabe715cb3467e5a2730c1b
7
+ data.tar.gz: 5d88573875acbb3cc6399c960f5c1f8ab7f4f7fa49f4c56254f3c11f25c76be9fc8632b88e94a1f635c54d6b2034113e30499822bf6412fc79925d4f8e4e9f78
@@ -57,6 +57,7 @@ RedactorPlugins.save = function()
57
57
  type: 'POST',
58
58
  url: post_url,
59
59
  data: {
60
+ identifier: identifier,
60
61
  route: route,
61
62
  content: html_content
62
63
  },
@@ -9,4 +9,10 @@
9
9
  * compiled file, but it's generally better to create a new file per style scope.
10
10
  *
11
11
  *= require annex/redactor
12
- */
12
+ */
13
+
14
+ .redactor {
15
+ box-shadow: inset 0 0 1px rgba(0, 0, 0, 0.1);
16
+ display: block;
17
+ min-height: 20px;
18
+ }
@@ -5,15 +5,10 @@ module Annex
5
5
 
6
6
  # POST /annex/blocks
7
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
8
+ @block = Block.builder(params)
14
9
 
15
10
  if @block.save
16
- render json: {status: :success}, status: :ok
11
+ render json: { status: :success }, status: :ok
17
12
  else
18
13
  render json: @block.errors, status: :unprocessable_entity
19
14
  end
@@ -1,17 +1,47 @@
1
+ #
2
+ # Block Model
3
+ #
4
+ # Stores the raw information in the database
5
+ #
1
6
  module Annex
2
- #
3
- # Block Model
4
- #
5
- # Stores the raw information in the database
6
- #
7
- class Block
8
- include Mongoid::Document
9
- include Mongoid::Timestamps
10
- include Mongoid::Attributes::Dynamic
11
-
12
- field :route, type: String
13
- field :content, type: Hash
14
-
15
- validates_presence_of :route
7
+
8
+ case Annex::config[:adapter]
9
+
10
+ when :activerecord
11
+ class Block < ActiveRecord::Base
12
+ validates_presence_of :route
13
+
14
+ def self.builder(params)
15
+ puts params.inspect.red
16
+
17
+ block = Block.where(route: "#{params[:route]}_#{params[:identifier]}").first_or_create
18
+ block.content = params[:content][params[:identifier].to_sym]
19
+
20
+ puts params[:content][params[:identifier].to_sym].inspect.red
21
+
22
+ return block
23
+ end
24
+ end
25
+
26
+ when :mongoid
27
+ class Block
28
+ field :route, type: String
29
+ field :content, type: Hash
30
+
31
+ validates_presence_of :route
32
+
33
+ def self.builder(params)
34
+ block = Block.where(route: params[:route]).first_or_create
35
+
36
+ block.content ||= {}
37
+
38
+ params[:content].keys.each do |key|
39
+ block.content[key] = params[:content][key]
40
+ end
41
+
42
+ return block
43
+ end
44
+ end
16
45
  end
46
+
17
47
  end
@@ -0,0 +1,8 @@
1
+ class AnnexBlock < ActiveRecord::Migration
2
+ def change
3
+ create_table :annex_blocks do |t|
4
+ t.string :route
5
+ t.text :content
6
+ end
7
+ end
8
+ end
data/lib/annex/config.rb CHANGED
@@ -82,6 +82,10 @@ module Annex
82
82
  @authorize || DEFAULT_AUTHORIZE
83
83
  end
84
84
 
85
+ def connect_with(adapter = :activerecord)
86
+ @adapter = adapter
87
+ end
88
+
85
89
  end
86
90
  end
87
91
  end
data/lib/annex/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Annex
3
3
  #
4
4
  module Annex
5
- VERSION = '0.2.1'
5
+ VERSION = '0.3.0'
6
6
  end
@@ -1,5 +1,3 @@
1
- require 'active_support/hash_with_indifferent_access'
2
-
3
1
  module Annex
4
2
  #
5
3
  # Create global view helpers
@@ -7,18 +5,24 @@ module Annex
7
5
  module ViewHelpers
8
6
  #
9
7
  # annex_block is a universal helper to render content from
10
- # mongodb and display it on the page
11
- #
12
- # @TODO: implement caching
8
+ # the database and display it on the page
13
9
  #
14
10
  def annex_block(identifier, opts = {})
15
11
  opts[:route] ||= current_route
16
12
 
17
- doc = Annex::Block.where(route: opts[:route]).first_or_create
13
+ case Annex::config[:adapter]
14
+
15
+ when :activerecord
16
+ doc = Annex::Block.where(route: "#{opts[:route]}_#{identifier}").first_or_create
17
+ content = doc.content
18
+
19
+ when :mongoid
20
+ doc = Annex::Block.where(route: opts[:route]).first_or_create
21
+ content = doc.content.try(:[], identifier.to_s)
18
22
 
19
- content = doc.content.try(:[], identifier.to_s) || opts[:default]
23
+ end
20
24
 
21
- render partial: 'annex/block', locals: { content: content, identifier: identifier, opts: opts }
25
+ render partial: 'annex/block', locals: { content: content || opts[:default], identifier: identifier, opts: opts }
22
26
  end
23
27
 
24
28
  def current_route
data/lib/annex-cms.rb CHANGED
@@ -5,4 +5,32 @@ require 'annex/extensions/cancan'
5
5
  require 'annex/railtie'
6
6
 
7
7
  module Annex
8
+ # Configuration defaults
9
+ @config = {
10
+ adapter: :activerecord
11
+ }
12
+
13
+ @valid_config_keys = @config.keys
14
+
15
+ # Configure through hash
16
+ def self.configure(opts = {})
17
+ opts.each { |k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym }
18
+ end
19
+
20
+ # Configure through yaml file
21
+ def self.configure_with(path_to_yaml_file)
22
+ begin
23
+ config = YAML::load(IO.read(path_to_yaml_file))
24
+ rescue Errno::ENOENT
25
+ log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
26
+ rescue Psych::SyntaxError
27
+ log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
28
+ end
29
+
30
+ configure(config)
31
+ end
32
+
33
+ def self.config
34
+ @config
35
+ end
8
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annex-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clay McIlrath
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.0'
27
- - !ruby/object:Gem::Dependency
28
- name: mongoid
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  description: An inline editor CMS powered by redactor, devise and mongodb. Up and
42
28
  running in seconds
43
29
  email:
@@ -65,11 +51,10 @@ files:
65
51
  - app/assets/stylesheets/annex/redactor.css.scss
66
52
  - app/controllers/annex/application_controller.rb
67
53
  - app/controllers/annex/blocks_controller.rb
68
- - app/controllers/annex/files_controller.rb
69
54
  - app/models/annex/block.rb
70
- - app/models/annex/file.rb
71
55
  - app/views/annex/_block.html.haml
72
56
  - config/routes.rb
57
+ - db/migrate/20141118200937_annex_block.rb
73
58
  - lib/annex-cms.rb
74
59
  - lib/annex/config.rb
75
60
  - lib/annex/engine.rb
@@ -1,12 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- module Annex
2
- class File
3
- include Mongoid::Document
4
- include Mongoid::Timestamps
5
- include Mongoid::Attributes::Dynamic
6
- end
7
- end