grat 0.2.4 → 0.3.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/Rakefile +1 -1
 - data/VERSION +1 -1
 - data/config.ru +1 -0
 - data/grat.gemspec +5 -5
 - data/lib/environment.rb +16 -18
 - data/lib/grat.rb +28 -27
 - data/lib/grat/content.rb +35 -35
 - metadata +4 -4
 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -13,7 +13,7 @@ begin 
     | 
|
| 
       13 
13 
     | 
    
         
             
                gem.add_development_dependency "yard", ">= 0"
         
     | 
| 
       14 
14 
     | 
    
         
             
                gem.add_runtime_dependency 'sinatra'
         
     | 
| 
       15 
15 
     | 
    
         
             
                gem.add_runtime_dependency 'haml'
         
     | 
| 
       16 
     | 
    
         
            -
                gem.add_runtime_dependency ' 
     | 
| 
      
 16 
     | 
    
         
            +
                gem.add_runtime_dependency 'mongo_mapper', "0.6.8"
         
     | 
| 
       17 
17 
     | 
    
         
             
                gem.add_runtime_dependency 'json'
         
     | 
| 
       18 
18 
     | 
    
         
             
                # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
         
     | 
| 
       19 
19 
     | 
    
         
             
              end
         
     | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.3.0
         
     | 
    
        data/config.ru
    CHANGED
    
    
    
        data/grat.gemspec
    CHANGED
    
    | 
         @@ -5,11 +5,11 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = %q{grat}
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.3.0"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["Sam Schenkman-Moore"]
         
     | 
| 
       12 
     | 
    
         
            -
              s.date = %q{2009-12- 
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = %q{2009-12-29}
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.description = %q{Basic interface for making webpages with Haml and Erb. Supports nested templates.}
         
     | 
| 
       14 
14 
     | 
    
         
             
              s.email = %q{samsm@samsm.com}
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.extra_rdoc_files = [
         
     | 
| 
         @@ -97,20 +97,20 @@ Gem::Specification.new do |s| 
     | 
|
| 
       97 
97 
     | 
    
         
             
                  s.add_development_dependency(%q<yard>, [">= 0"])
         
     | 
| 
       98 
98 
     | 
    
         
             
                  s.add_runtime_dependency(%q<sinatra>, [">= 0"])
         
     | 
| 
       99 
99 
     | 
    
         
             
                  s.add_runtime_dependency(%q<haml>, [">= 0"])
         
     | 
| 
       100 
     | 
    
         
            -
                  s.add_runtime_dependency(%q< 
     | 
| 
      
 100 
     | 
    
         
            +
                  s.add_runtime_dependency(%q<mongo_mapper>, ["= 0.6.8"])
         
     | 
| 
       101 
101 
     | 
    
         
             
                  s.add_runtime_dependency(%q<json>, [">= 0"])
         
     | 
| 
       102 
102 
     | 
    
         
             
                else
         
     | 
| 
       103 
103 
     | 
    
         
             
                  s.add_dependency(%q<yard>, [">= 0"])
         
     | 
| 
       104 
104 
     | 
    
         
             
                  s.add_dependency(%q<sinatra>, [">= 0"])
         
     | 
| 
       105 
105 
     | 
    
         
             
                  s.add_dependency(%q<haml>, [">= 0"])
         
     | 
| 
       106 
     | 
    
         
            -
                  s.add_dependency(%q< 
     | 
| 
      
 106 
     | 
    
         
            +
                  s.add_dependency(%q<mongo_mapper>, ["= 0.6.8"])
         
     | 
| 
       107 
107 
     | 
    
         
             
                  s.add_dependency(%q<json>, [">= 0"])
         
     | 
| 
       108 
108 
     | 
    
         
             
                end
         
     | 
| 
       109 
109 
     | 
    
         
             
              else
         
     | 
| 
       110 
110 
     | 
    
         
             
                s.add_dependency(%q<yard>, [">= 0"])
         
     | 
| 
       111 
111 
     | 
    
         
             
                s.add_dependency(%q<sinatra>, [">= 0"])
         
     | 
| 
       112 
112 
     | 
    
         
             
                s.add_dependency(%q<haml>, [">= 0"])
         
     | 
| 
       113 
     | 
    
         
            -
                s.add_dependency(%q< 
     | 
| 
      
 113 
     | 
    
         
            +
                s.add_dependency(%q<mongo_mapper>, ["= 0.6.8"])
         
     | 
| 
       114 
114 
     | 
    
         
             
                s.add_dependency(%q<json>, [">= 0"])
         
     | 
| 
       115 
115 
     | 
    
         
             
              end
         
     | 
| 
       116 
116 
     | 
    
         
             
            end
         
     | 
    
        data/lib/environment.rb
    CHANGED
    
    | 
         @@ -7,40 +7,38 @@ module Grat 
     | 
|
| 
       7 
7 
     | 
    
         
             
              def self.root_path
         
     | 
| 
       8 
8 
     | 
    
         
             
                File.dirname(File.dirname(__FILE__))
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       11 
11 
     | 
    
         
             
              def self.lib_path
         
     | 
| 
       12 
12 
     | 
    
         
             
                root_path + '/lib'
         
     | 
| 
       13 
13 
     | 
    
         
             
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
       15 
15 
     | 
    
         
             
              def self.view_path
         
     | 
| 
       16 
16 
     | 
    
         
             
                root_path + '/views'
         
     | 
| 
       17 
17 
     | 
    
         
             
              end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       19 
19 
     | 
    
         
             
              def self.database_conf(options = {})
         
     | 
| 
       20 
20 
     | 
    
         
             
                @@database_conf = options
         
     | 
| 
       21 
21 
     | 
    
         
             
              end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
       23 
23 
     | 
    
         
             
              def self.database_load
         
     | 
| 
       24 
     | 
    
         
            -
                require ' 
     | 
| 
       25 
     | 
    
         
            -
                 
     | 
| 
       26 
     | 
    
         
            -
                  Mongo::Connection.new(@@database_conf[:host])
         
     | 
| 
       27 
     | 
    
         
            -
                else
         
     | 
| 
       28 
     | 
    
         
            -
                  Mongo::Connection.new
         
     | 
| 
      
 24 
     | 
    
         
            +
                require 'mongo_mapper'
         
     | 
| 
      
 25 
     | 
    
         
            +
                if @@database_conf[:host]
         
     | 
| 
      
 26 
     | 
    
         
            +
                  MongoMapper.connection = Mongo::Connection.new(@@database_conf[:host])
         
     | 
| 
       29 
27 
     | 
    
         
             
                end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                database = @@ 
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                MongoMapper.database = @@database_conf[:database] || 'grat_development'
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
       32 
31 
     | 
    
         
             
                if @@database_conf[:username] && @@database_conf[:password]
         
     | 
| 
       33 
     | 
    
         
            -
                  database.authenticate(@@database_conf[:username], @@database_conf[:password])
         
     | 
| 
      
 32 
     | 
    
         
            +
                  MongoMapper.database.authenticate(@@database_conf[:username], @@database_conf[:password])
         
     | 
| 
       34 
33 
     | 
    
         
             
                end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                Mongoid.database = database
         
     | 
| 
       37 
     | 
    
         
            -
                
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       38 
35 
     | 
    
         
             
                require Grat.lib_path + '/grat/content'
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
       40 
37 
     | 
    
         
             
              end
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
       42 
40 
     | 
    
         
             
              def self.database
         
     | 
| 
       43 
     | 
    
         
            -
                 
     | 
| 
      
 41 
     | 
    
         
            +
                MongoMapper.database
         
     | 
| 
       44 
42 
     | 
    
         
             
              end
         
     | 
| 
       45 
43 
     | 
    
         
             
            end
         
     | 
| 
       46 
44 
     | 
    
         | 
    
        data/lib/grat.rb
    CHANGED
    
    | 
         @@ -1,12 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require File.dirname(__FILE__) + '/environment.rb'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class Grat::Application < Sinatra::Base
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
       5 
5 
     | 
    
         
             
              include Grat::System
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       7 
7 
     | 
    
         
             
              set :views, Grat.view_path
         
     | 
| 
       8 
8 
     | 
    
         
             
              set :methodoverride, true
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
       10 
10 
     | 
    
         
             
              # serve some static assets directly from gem
         
     | 
| 
       11 
11 
     | 
    
         
             
              get '/gratfiles/:filename' do
         
     | 
| 
       12 
12 
     | 
    
         
             
                file_data = IO.read(Grat.root_path + '/public/gratfiles/' + params[:filename])
         
     | 
| 
         @@ -18,30 +18,30 @@ class Grat::Application < Sinatra::Base 
     | 
|
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         
             
                file_data
         
     | 
| 
       20 
20 
     | 
    
         
             
              end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
       22 
22 
     | 
    
         
             
              get '/__admin/all' do
         
     | 
| 
       23 
23 
     | 
    
         
             
                @pages = model.all
         
     | 
| 
       24 
24 
     | 
    
         
             
                @templates = templates
         
     | 
| 
       25 
25 
     | 
    
         
             
                haml :list
         
     | 
| 
       26 
26 
     | 
    
         
             
              end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       28 
28 
     | 
    
         
             
              get '/__admin/export' do
         
     | 
| 
       29 
29 
     | 
    
         
             
                content_type('text/json')
         
     | 
| 
       30 
30 
     | 
    
         
             
                # Content-disposition: attachment; filename=fname.ext
         
     | 
| 
       31 
31 
     | 
    
         
             
                response['Content-disposition'] = "attachment; filename=grat-#{request.host}-export-at-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.json"
         
     | 
| 
       32 
32 
     | 
    
         
             
                model.all.to_json
         
     | 
| 
       33 
33 
     | 
    
         
             
              end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       35 
35 
     | 
    
         
             
              get '/__admin/import' do
         
     | 
| 
       36 
36 
     | 
    
         
             
                haml :import_form
         
     | 
| 
       37 
37 
     | 
    
         
             
              end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
       39 
39 
     | 
    
         
             
              post '/__admin/import' do
         
     | 
| 
       40 
40 
     | 
    
         
             
                json_text = file_import_text || params[:import][:text]
         
     | 
| 
       41 
41 
     | 
    
         
             
                @import_results = import(json_text, params[:import][:strategy])
         
     | 
| 
       42 
42 
     | 
    
         
             
                redirect '/__admin/all'
         
     | 
| 
       43 
43 
     | 
    
         
             
              end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
       45 
45 
     | 
    
         
             
              # Rather inefficient at present.
         
     | 
| 
       46 
46 
     | 
    
         
             
              def import(json_text, strategy)
         
     | 
| 
       47 
47 
     | 
    
         
             
                json_to_import = JSON.parse json_text
         
     | 
| 
         @@ -59,7 +59,7 @@ class Grat::Application < Sinatra::Base 
     | 
|
| 
       59 
59 
     | 
    
         
             
                  end
         
     | 
| 
       60 
60 
     | 
    
         
             
                end
         
     | 
| 
       61 
61 
     | 
    
         
             
              end
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
       63 
63 
     | 
    
         
             
              def import_record(hash, options = {:replace => false, :check => true})
         
     | 
| 
       64 
64 
     | 
    
         
             
                record = model.find_by_url(hash['url']) if options[:check]
         
     | 
| 
       65 
65 
     | 
    
         
             
                if record && options[:replace]
         
     | 
| 
         @@ -69,21 +69,21 @@ class Grat::Application < Sinatra::Base 
     | 
|
| 
       69 
69 
     | 
    
         
             
                  model.create hash
         
     | 
| 
       70 
70 
     | 
    
         
             
                end
         
     | 
| 
       71 
71 
     | 
    
         
             
              end
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
       73 
73 
     | 
    
         
             
              def file_import_text
         
     | 
| 
       74 
74 
     | 
    
         
             
                if params[:import] && params[:import][:file] && params[:import][:file][:tempfile]
         
     | 
| 
       75 
75 
     | 
    
         
             
                  params[:import][:file][:tempfile].read
         
     | 
| 
       76 
76 
     | 
    
         
             
                end
         
     | 
| 
       77 
77 
     | 
    
         
             
              end
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
       79 
79 
     | 
    
         
             
              get '/__admin/edit/*' do
         
     | 
| 
       80 
80 
     | 
    
         
             
                haml :content_form
         
     | 
| 
       81 
81 
     | 
    
         
             
              end
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
       83 
83 
     | 
    
         
             
              get '/__admin/delete/*' do
         
     | 
| 
       84 
84 
     | 
    
         
             
                haml :delete
         
     | 
| 
       85 
85 
     | 
    
         
             
              end
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
       87 
87 
     | 
    
         
             
              get '/__admin/new' do
         
     | 
| 
       88 
88 
     | 
    
         
             
                url = params[:url]
         
     | 
| 
       89 
89 
     | 
    
         
             
                if url.to_s[/./]
         
     | 
| 
         @@ -101,18 +101,19 @@ class Grat::Application < Sinatra::Base 
     | 
|
| 
       101 
101 
     | 
    
         
             
                  end
         
     | 
| 
       102 
102 
     | 
    
         
             
                end
         
     | 
| 
       103 
103 
     | 
    
         
             
              end
         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
       105 
105 
     | 
    
         
             
              put '/*' do
         
     | 
| 
       106 
106 
     | 
    
         
             
                content.update_attributes(focus_params)
         
     | 
| 
       107 
107 
     | 
    
         
             
                redirect edit_path(content.url)
         
     | 
| 
       108 
108 
     | 
    
         
             
              end
         
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
       110 
110 
     | 
    
         
             
              delete '/*' do
         
     | 
| 
       111 
111 
     | 
    
         
             
                content.destroy
         
     | 
| 
       112 
112 
     | 
    
         
             
                redirect edit_path(content.url)
         
     | 
| 
       113 
113 
     | 
    
         
             
              end
         
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
       115 
115 
     | 
    
         
             
              post '/*' do
         
     | 
| 
      
 116 
     | 
    
         
            +
                # debugger
         
     | 
| 
       116 
117 
     | 
    
         
             
                content.update_attributes(focus_params)
         
     | 
| 
       117 
118 
     | 
    
         
             
                if params[:content][:submit].include? 'make'
         
     | 
| 
       118 
119 
     | 
    
         
             
                  redirect edit_path(next_content_url)
         
     | 
| 
         @@ -120,7 +121,7 @@ class Grat::Application < Sinatra::Base 
     | 
|
| 
       120 
121 
     | 
    
         
             
                  redirect edit_path(content.url)
         
     | 
| 
       121 
122 
     | 
    
         
             
                end
         
     | 
| 
       122 
123 
     | 
    
         
             
              end
         
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
       124 
125 
     | 
    
         
             
              def next_content_url
         
     | 
| 
       125 
126 
     | 
    
         
             
                current_content = content
         
     | 
| 
       126 
127 
     | 
    
         
             
                new_url = '/broken'
         
     | 
| 
         @@ -137,10 +138,10 @@ class Grat::Application < Sinatra::Base 
     | 
|
| 
       137 
138 
     | 
    
         
             
                  new_url
         
     | 
| 
       138 
139 
     | 
    
         
             
                end
         
     | 
| 
       139 
140 
     | 
    
         
             
              end
         
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
       141 
142 
     | 
    
         
             
              get '/*' do
         
     | 
| 
       142 
143 
     | 
    
         
             
                pass if content.new_record?
         
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
       144 
145 
     | 
    
         
             
                case request_type
         
     | 
| 
       145 
146 
     | 
    
         
             
                when 'html'
         
     | 
| 
       146 
147 
     | 
    
         
             
                  locals = {}
         
     | 
| 
         @@ -155,36 +156,36 @@ class Grat::Application < Sinatra::Base 
     | 
|
| 
       155 
156 
     | 
    
         
             
                  content.to_json
         
     | 
| 
       156 
157 
     | 
    
         
             
                end
         
     | 
| 
       157 
158 
     | 
    
         
             
              end
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
       159 
160 
     | 
    
         
             
              not_found do
         
     | 
| 
       160 
161 
     | 
    
         
             
                haml :missing
         
     | 
| 
       161 
162 
     | 
    
         
             
              end
         
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
       163 
164 
     | 
    
         
             
              def edit_path(url)
         
     | 
| 
       164 
165 
     | 
    
         
             
                "/__admin/edit#{url}"
         
     | 
| 
       165 
166 
     | 
    
         
             
              end
         
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
       167 
168 
     | 
    
         
             
              def delete_path(url)
         
     | 
| 
       168 
169 
     | 
    
         
             
                "/__admin/delete#{url}"
         
     | 
| 
       169 
170 
     | 
    
         
             
              end
         
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
       171 
172 
     | 
    
         
             
              def combine_docs(text,template,vars)
         
     | 
| 
       172 
173 
     | 
    
         
             
                template.content_with(vars,text)
         
     | 
| 
       173 
174 
     | 
    
         
             
              end
         
     | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
       175 
176 
     | 
    
         
             
              def haml(*args)
         
     | 
| 
       176 
177 
     | 
    
         
             
                require 'haml'
         
     | 
| 
       177 
178 
     | 
    
         
             
                super(*args)
         
     | 
| 
       178 
179 
     | 
    
         
             
              end
         
     | 
| 
       179 
     | 
    
         
            -
             
     | 
| 
      
 180 
     | 
    
         
            +
             
     | 
| 
       180 
181 
     | 
    
         
             
              def templates
         
     | 
| 
       181 
182 
     | 
    
         
             
                model.find_all_by_tag('template')
         
     | 
| 
       182 
183 
     | 
    
         
             
              end
         
     | 
| 
       183 
     | 
    
         
            -
             
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
       184 
185 
     | 
    
         
             
              helpers do
         
     | 
| 
       185 
186 
     | 
    
         
             
                def form_nest(name)
         
     | 
| 
       186 
187 
     | 
    
         
             
                  "content[#{name}]"
         
     | 
| 
       187 
188 
     | 
    
         
             
                end
         
     | 
| 
       188 
189 
     | 
    
         
             
              end
         
     | 
| 
       189 
     | 
    
         
            -
             
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
       190 
191 
     | 
    
         
             
            end
         
     | 
    
        data/lib/grat/content.rb
    CHANGED
    
    | 
         @@ -1,75 +1,75 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class Grat::Content 
     | 
| 
       2 
     | 
    
         
            -
              include  
     | 
| 
      
 1 
     | 
    
         
            +
            class Grat::Content
         
     | 
| 
      
 2 
     | 
    
         
            +
              include MongoMapper::Document
         
     | 
| 
       3 
3 
     | 
    
         
             
              attr_accessor :suggested_fields
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              key :url
         
     | 
| 
       6 
6 
     | 
    
         
             
              validates_uniqueness_of :url
         
     | 
| 
       7 
     | 
    
         
            -
               
     | 
| 
       8 
     | 
    
         
            -
               
     | 
| 
       9 
     | 
    
         
            -
               
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
              key :content
         
     | 
| 
      
 8 
     | 
    
         
            +
              key :tags, Array
         
     | 
| 
      
 9 
     | 
    
         
            +
              key :template_url
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       11 
11 
     | 
    
         
             
              before_save :detect_default_content_vars
         
     | 
| 
       12 
     | 
    
         
            -
               
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 12 
     | 
    
         
            +
              key :default_content_vars, Hash
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
       14 
14 
     | 
    
         
             
              def attributes_for_variables
         
     | 
| 
       15 
15 
     | 
    
         
             
                attributes.reject {|k,v| k == '_id' }
         
     | 
| 
       16 
16 
     | 
    
         
             
              end
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
       18 
18 
     | 
    
         
             
              def editable_fields
         
     | 
| 
       19 
19 
     | 
    
         
             
                attributes.reject {|k,v| uneditable_keys.include? k }
         
     | 
| 
       20 
20 
     | 
    
         
             
              end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
       22 
22 
     | 
    
         
             
              def uneditable_keys
         
     | 
| 
       23 
23 
     | 
    
         
             
                # url is in here so it can maually be placed at the top of edit form.
         
     | 
| 
       24 
24 
     | 
    
         
             
                # Same deal with template_url
         
     | 
| 
       25 
25 
     | 
    
         
             
                ["updated_at", "_id", "url", "created_at","content","tags",'template_url','template',
         
     | 
| 
       26 
26 
     | 
    
         
             
                  'default_content_vars','variables_needed','render_engine_name']
         
     | 
| 
       27 
27 
     | 
    
         
             
              end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
       29 
29 
     | 
    
         
             
              def tags=(val)
         
     | 
| 
       30 
     | 
    
         
            -
                 
     | 
| 
      
 30 
     | 
    
         
            +
                super(val.kind_of?(Array) ? val : val.split(' '))
         
     | 
| 
       31 
31 
     | 
    
         
             
              end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
       33 
33 
     | 
    
         
             
              def tags
         
     | 
| 
       34 
     | 
    
         
            -
                 
     | 
| 
      
 34 
     | 
    
         
            +
                super or []
         
     | 
| 
       35 
35 
     | 
    
         
             
              end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
       37 
37 
     | 
    
         
             
              def self.find_all_by_tag(tag_name)
         
     | 
| 
       38 
38 
     | 
    
         
             
                all(:conditions => {'tags' => [tag_name]})
         
     | 
| 
       39 
39 
     | 
    
         
             
              end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
       41 
41 
     | 
    
         
             
              def type
         
     | 
| 
       42 
42 
     | 
    
         
             
                self.class.to_s.sub(/.+::/, '')
         
     | 
| 
       43 
43 
     | 
    
         
             
              end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
       45 
45 
     | 
    
         
             
              def default_content_vars
         
     | 
| 
       46 
     | 
    
         
            -
                 
     | 
| 
      
 46 
     | 
    
         
            +
                super or {}
         
     | 
| 
       47 
47 
     | 
    
         
             
              end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
       49 
49 
     | 
    
         
             
              def default_content_vars=(val)
         
     | 
| 
       50 
     | 
    
         
            -
                 
     | 
| 
      
 50 
     | 
    
         
            +
                super val.kind_of?(String) ? JSON.parse(val) : val
         
     | 
| 
       51 
51 
     | 
    
         
             
              end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
       53 
53 
     | 
    
         
             
              def template
         
     | 
| 
       54 
54 
     | 
    
         
             
                @template ||= Grat::Content.find_by_url(template_url) if template_url
         
     | 
| 
       55 
55 
     | 
    
         
             
              end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
       57 
57 
     | 
    
         
             
              def template=(var)
         
     | 
| 
       58 
58 
     | 
    
         
             
                raise 'This is probably a mistake.'
         
     | 
| 
       59 
59 
     | 
    
         
             
              end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
       61 
61 
     | 
    
         
             
              def template_url=(var)
         
     | 
| 
       62 
     | 
    
         
            -
                 
     | 
| 
      
 62 
     | 
    
         
            +
                super(var) unless var.nil? || var.empty?
         
     | 
| 
       63 
63 
     | 
    
         
             
              end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
       65 
65 
     | 
    
         
             
              def demo_string
         
     | 
| 
       66 
66 
     | 
    
         
             
                'String needed'
         
     | 
| 
       67 
67 
     | 
    
         
             
              end
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
       69 
69 
     | 
    
         
             
              def demo_array
         
     | 
| 
       70 
70 
     | 
    
         
             
                %w(an array is needed)
         
     | 
| 
       71 
71 
     | 
    
         
             
              end
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
       73 
73 
     | 
    
         
             
              def render_engine
         
     | 
| 
       74 
74 
     | 
    
         
             
                if content.match(/\A[!%#.=-]/)
         
     | 
| 
       75 
75 
     | 
    
         
             
                  :haml
         
     | 
| 
         @@ -77,7 +77,7 @@ class Grat::Content < Mongoid::Document 
     | 
|
| 
       77 
77 
     | 
    
         
             
                  :erb
         
     | 
| 
       78 
78 
     | 
    
         
             
                end
         
     | 
| 
       79 
79 
     | 
    
         
             
              end
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
       81 
81 
     | 
    
         
             
              def detect_default_content_vars
         
     | 
| 
       82 
82 
     | 
    
         
             
                counter = 0
         
     | 
| 
       83 
83 
     | 
    
         
             
                while problem_var = detect_problem_var
         
     | 
| 
         @@ -90,18 +90,18 @@ class Grat::Content < Mongoid::Document 
     | 
|
| 
       90 
90 
     | 
    
         
             
                  raise "Don't know how to reconcile."
         
     | 
| 
       91 
91 
     | 
    
         
             
                end
         
     | 
| 
       92 
92 
     | 
    
         
             
              end
         
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
       94 
94 
     | 
    
         
             
              def haml_render(text, template, vars)
         
     | 
| 
       95 
95 
     | 
    
         
             
                require 'haml'
         
     | 
| 
       96 
96 
     | 
    
         
             
                haml_template = Haml::Engine.new(template)
         
     | 
| 
       97 
97 
     | 
    
         
             
                haml_template.render(haml_template, vars) { text }
         
     | 
| 
       98 
98 
     | 
    
         
             
              end
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
       100 
100 
     | 
    
         
             
              def erb_render(text, template, vars)
         
     | 
| 
       101 
101 
     | 
    
         
             
                require 'erb'
         
     | 
| 
       102 
102 
     | 
    
         
             
                ERB.new(template,0).result(Grat::HashBinding.new(vars).get_binding { text })
         
     | 
| 
       103 
103 
     | 
    
         
             
              end
         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
       105 
105 
     | 
    
         
             
              def detect_problem_var(resolution = {})
         
     | 
| 
       106 
106 
     | 
    
         
             
                begin
         
     | 
| 
       107 
107 
     | 
    
         
             
                  rendered = content_with(default_content_vars.merge(resolution), problem_var = nil)
         
     | 
| 
         @@ -110,11 +110,11 @@ class Grat::Content < Mongoid::Document 
     | 
|
| 
       110 
110 
     | 
    
         
             
                  $!.to_s.sub(/.+`/,'').sub(/'.+/,'')
         
     | 
| 
       111 
111 
     | 
    
         
             
                end
         
     | 
| 
       112 
112 
     | 
    
         
             
              end
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
       114 
114 
     | 
    
         
             
              def content_with(locals = {},y = '')
         
     | 
| 
       115 
115 
     | 
    
         
             
                send "#{render_engine}_render", y, content, locals
         
     | 
| 
       116 
116 
     | 
    
         
             
              end
         
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
       118 
118 
     | 
    
         
             
              def suggested_fields
         
     | 
| 
       119 
119 
     | 
    
         
             
                @suggested_fields or []
         
     | 
| 
       120 
120 
     | 
    
         
             
              end
         
     | 
    
        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.3.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- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2009-12-29 00:00:00 -05:00
         
     | 
| 
       13 
13 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -43,14 +43,14 @@ dependencies: 
     | 
|
| 
       43 
43 
     | 
    
         
             
                    version: "0"
         
     | 
| 
       44 
44 
     | 
    
         
             
                version: 
         
     | 
| 
       45 
45 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       46 
     | 
    
         
            -
              name:  
     | 
| 
      
 46 
     | 
    
         
            +
              name: mongo_mapper
         
     | 
| 
       47 
47 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       48 
48 
     | 
    
         
             
              version_requirement: 
         
     | 
| 
       49 
49 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement 
         
     | 
| 
       50 
50 
     | 
    
         
             
                requirements: 
         
     | 
| 
       51 
51 
     | 
    
         
             
                - - "="
         
     | 
| 
       52 
52 
     | 
    
         
             
                  - !ruby/object:Gem::Version 
         
     | 
| 
       53 
     | 
    
         
            -
                    version: 0. 
     | 
| 
      
 53 
     | 
    
         
            +
                    version: 0.6.8
         
     | 
| 
       54 
54 
     | 
    
         
             
                version: 
         
     | 
| 
       55 
55 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       56 
56 
     | 
    
         
             
              name: json
         
     |