grat 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/environment.rb +15 -7
- data/lib/grat/content.rb +8 -10
- data/lib/grat/system.rb +2 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -32,7 +32,7 @@ Use it like so:
|
|
32
32
|
9. Protect from writes by strangers with Rack::If
|
33
33
|
# http://github.com/samsm/Rackif
|
34
34
|
|
35
|
-
use Rack::If, :method => /(POST)|(PUT)|(DELETE)/ do
|
35
|
+
use Rack::If, {:method => /(POST)|(PUT)|(DELETE)/, :path => /__admin/}, :any do
|
36
36
|
use Rack::Auth::Basic, "Grat protected" do |username, password|
|
37
37
|
'secret' == password
|
38
38
|
end
|
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ begin
|
|
14
14
|
gem.add_development_dependency "yard", ">= 0"
|
15
15
|
gem.add_runtime_dependency 'sinatra'
|
16
16
|
gem.add_runtime_dependency 'haml'
|
17
|
-
gem.add_runtime_dependency '
|
17
|
+
gem.add_runtime_dependency 'mongoid'
|
18
18
|
gem.add_runtime_dependency 'json'
|
19
19
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
20
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/environment.rb
CHANGED
@@ -2,6 +2,7 @@ require 'sinatra'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
module Grat
|
5
|
+
@@connection = nil
|
5
6
|
@@database_conf = {}
|
6
7
|
def self.root_path
|
7
8
|
File.dirname(File.dirname(__FILE__))
|
@@ -20,20 +21,27 @@ module Grat
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def self.database_load
|
23
|
-
require '
|
24
|
-
if @@database_conf[:host]
|
25
|
-
|
24
|
+
require 'mongoid'
|
25
|
+
@@connection = if @@database_conf[:host]
|
26
|
+
Mongo::Connection.new(@@database_conf[:host])
|
27
|
+
else
|
28
|
+
Mongo::Connection.new
|
26
29
|
end
|
27
30
|
|
28
|
-
|
29
|
-
|
31
|
+
database = @@connection.db(@@database_conf[:database] || 'grat_development')
|
30
32
|
if @@database_conf[:username] && @@database_conf[:password]
|
31
|
-
|
33
|
+
database.authenticate(@@database_conf[:username], @@database_conf[:password])
|
32
34
|
end
|
33
|
-
|
35
|
+
|
36
|
+
Mongoid.database = database
|
37
|
+
|
34
38
|
require Grat.lib_path + '/grat/content'
|
35
39
|
|
36
40
|
end
|
41
|
+
|
42
|
+
def self.database
|
43
|
+
Mongoid.database
|
44
|
+
end
|
37
45
|
end
|
38
46
|
|
39
47
|
require Grat.lib_path + '/grat/system'
|
data/lib/grat/content.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
|
-
class Grat::Content
|
2
|
-
include
|
3
|
-
|
1
|
+
class Grat::Content < Mongoid::Document
|
2
|
+
include Mongoid::Timestamps
|
4
3
|
attr_accessor :suggested_fields
|
5
4
|
|
6
|
-
|
5
|
+
field :url
|
7
6
|
validates_uniqueness_of :url
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
timestamps!
|
7
|
+
field :content
|
8
|
+
field :tags, :type => Array
|
9
|
+
field :template_url
|
12
10
|
|
13
11
|
before_save :detect_default_content_vars
|
14
|
-
|
12
|
+
field :default_content_vars, :type => Hash
|
15
13
|
|
16
14
|
def attributes_for_variables
|
17
15
|
attributes.reject {|k,v| k == '_id' }
|
@@ -41,7 +39,7 @@ class Grat::Content
|
|
41
39
|
end
|
42
40
|
|
43
41
|
def default_content_vars
|
44
|
-
|
42
|
+
@default_content_vars or {}
|
45
43
|
end
|
46
44
|
|
47
45
|
def template
|
data/lib/grat/system.rb
CHANGED
@@ -47,8 +47,8 @@ module Grat::System
|
|
47
47
|
def model
|
48
48
|
return @model if @model
|
49
49
|
|
50
|
-
# Sinatra reloads are slow when
|
51
|
-
# This avoids requiring
|
50
|
+
# Sinatra reloads are slow when mongoid has to re-require
|
51
|
+
# This avoids requiring mongoid when it isn't needed
|
52
52
|
Grat.database_load
|
53
53
|
|
54
54
|
@model = Grat::Content
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Schenkman-Moore
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-10 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: "0"
|
44
44
|
version:
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
|
-
name:
|
46
|
+
name: mongoid
|
47
47
|
type: :runtime
|
48
48
|
version_requirement:
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|