grat 0.0.5.2 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +1 -0
- data/README +7 -1
- data/Rakefile +1 -1
- data/grat.gemspec +3 -3
- data/lib/environment.rb +1 -0
- data/lib/grat/content.rb +3 -3
- data/lib/grat.rb +51 -0
- data/public/gratfiles/custom.css +13 -1
- data/views/import_form.haml +24 -0
- metadata +3 -2
data/Manifest
CHANGED
data/README
CHANGED
@@ -18,4 +18,10 @@ Use it like so:
|
|
18
18
|
|
19
19
|
use Rack::ShowExceptions # <- Up to you.
|
20
20
|
run Grat::Application
|
21
|
-
4. rackup (or passenger, if you know how)
|
21
|
+
4. rackup (or passenger, if you know how)
|
22
|
+
|
23
|
+
5. http://localhost:9292/admin/ (or whatever host:port) to add content.
|
24
|
+
6. http://localhost:9292/admin/mypage edits a page that will be available at http://localhost:9292/mypage
|
25
|
+
7. http://localhost:9292/admin/__all for a list of all pages
|
26
|
+
8. http://localhost:9292/admin/__export to get a json dump of all pages
|
27
|
+
9. http://localhost:9292/admin/__import to import one of those dumps
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
|
|
3
3
|
require 'rake'
|
4
4
|
require 'echoe'
|
5
5
|
|
6
|
-
Echoe.new('grat', '0.0.
|
6
|
+
Echoe.new('grat', '0.0.6') do |p|
|
7
7
|
p.summary = "Minimal CMS for Rack and MongoDB."
|
8
8
|
p.description = "Basic interface for making webpages with Haml and Erb. Supports nested templates."
|
9
9
|
p.url = "http://samsm.com/"
|
data/grat.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{grat}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.6"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Sam Schenkman-Moore"]
|
9
|
-
s.date = %q{2009-11-
|
9
|
+
s.date = %q{2009-11-09}
|
10
10
|
s.description = %q{Basic interface for making webpages with Haml and Erb. Supports nested templates.}
|
11
11
|
s.email = %q{samsm@samsm.com}
|
12
12
|
s.extra_rdoc_files = ["README", "lib/environment.rb", "lib/grat.rb", "lib/grat/content.rb", "lib/grat/hash_binding.rb", "lib/grat/mongomapper_patches.rb", "lib/grat/system.rb"]
|
13
|
-
s.files = ["Manifest", "README", "Rakefile", "config.ru", "lib/environment.rb", "lib/grat.rb", "lib/grat/content.rb", "lib/grat/hash_binding.rb", "lib/grat/mongomapper_patches.rb", "lib/grat/system.rb", "public/gratfiles/application.js", "public/gratfiles/custom.css", "public/gratfiles/einars-js-beautify/HTML-Beautify.js", "public/gratfiles/einars-js-beautify/beautify-cl.js", "public/gratfiles/einars-js-beautify/beautify-tests.js", "public/gratfiles/einars-js-beautify/beautify.js", "public/gratfiles/einars-js-beautify/bin/beautify_js", "public/gratfiles/einars-js-beautify/index.html", "public/gratfiles/einars-js-beautify/javascriptobfuscator_unpacker.js", "public/gratfiles/einars-js-beautify/license.txt", "public/gratfiles/einars-js-beautify/sanitytest.js", "public/gratfiles/einars-js-beautify/unmaintained/bbedit/jsBeautify_BBED.scpt", "public/gratfiles/einars-js-beautify/unmaintained/c-sharp/JSBeautify.cs", "public/gratfiles/einars-js-beautify/unmaintained/opera-userscript/make_opera_userscript.sh", "public/gratfiles/einars-js-beautify/unmaintained/opera-userscript/opera_userscript.js", "public/gratfiles/favicon.ico", "public/gratfiles/jquery-combined.min.js", "public/gratfiles/js-beautifier.min.js", "public/gratfiles/oocss.min.css", "public/gratfiles/oocss/content.css", "public/gratfiles/oocss/grids.css", "public/gratfiles/oocss/grids_debug.css", "public/gratfiles/oocss/libraries.css", "public/gratfiles/oocss/mod.css", "public/gratfiles/oocss/mod_debug.css", "public/gratfiles/oocss/mod_skins.css", "public/gratfiles/oocss/talk.css", "public/gratfiles/oocss/talk_skins.css", "public/gratfiles/oocss/template.css", "public/gratfiles/oocss/template_debug.css", "views/content_form.haml", "views/css/_content.sass", "views/css/_custom.sass", "views/css/_grids.sass", "views/css/_grids_debug.sass", "views/css/_libraries.sass", "views/css/_mod.sass", "views/css/_mod_debug.sass", "views/css/_mod_skins.sass", "views/css/_template.sass", "views/css/_template_debug.sass", "views/layout.haml", "views/list.haml", "views/missing.haml", "grat.gemspec"]
|
13
|
+
s.files = ["Manifest", "README", "Rakefile", "config.ru", "lib/environment.rb", "lib/grat.rb", "lib/grat/content.rb", "lib/grat/hash_binding.rb", "lib/grat/mongomapper_patches.rb", "lib/grat/system.rb", "public/gratfiles/application.js", "public/gratfiles/custom.css", "public/gratfiles/einars-js-beautify/HTML-Beautify.js", "public/gratfiles/einars-js-beautify/beautify-cl.js", "public/gratfiles/einars-js-beautify/beautify-tests.js", "public/gratfiles/einars-js-beautify/beautify.js", "public/gratfiles/einars-js-beautify/bin/beautify_js", "public/gratfiles/einars-js-beautify/index.html", "public/gratfiles/einars-js-beautify/javascriptobfuscator_unpacker.js", "public/gratfiles/einars-js-beautify/license.txt", "public/gratfiles/einars-js-beautify/sanitytest.js", "public/gratfiles/einars-js-beautify/unmaintained/bbedit/jsBeautify_BBED.scpt", "public/gratfiles/einars-js-beautify/unmaintained/c-sharp/JSBeautify.cs", "public/gratfiles/einars-js-beautify/unmaintained/opera-userscript/make_opera_userscript.sh", "public/gratfiles/einars-js-beautify/unmaintained/opera-userscript/opera_userscript.js", "public/gratfiles/favicon.ico", "public/gratfiles/jquery-combined.min.js", "public/gratfiles/js-beautifier.min.js", "public/gratfiles/oocss.min.css", "public/gratfiles/oocss/content.css", "public/gratfiles/oocss/grids.css", "public/gratfiles/oocss/grids_debug.css", "public/gratfiles/oocss/libraries.css", "public/gratfiles/oocss/mod.css", "public/gratfiles/oocss/mod_debug.css", "public/gratfiles/oocss/mod_skins.css", "public/gratfiles/oocss/talk.css", "public/gratfiles/oocss/talk_skins.css", "public/gratfiles/oocss/template.css", "public/gratfiles/oocss/template_debug.css", "views/content_form.haml", "views/css/_content.sass", "views/css/_custom.sass", "views/css/_grids.sass", "views/css/_grids_debug.sass", "views/css/_libraries.sass", "views/css/_mod.sass", "views/css/_mod_debug.sass", "views/css/_mod_skins.sass", "views/css/_template.sass", "views/css/_template_debug.sass", "views/import_form.haml", "views/layout.haml", "views/list.haml", "views/missing.haml", "grat.gemspec"]
|
14
14
|
s.homepage = %q{http://samsm.com/}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Grat", "--main", "README"]
|
16
16
|
s.require_paths = ["lib"]
|
data/lib/environment.rb
CHANGED
data/lib/grat/content.rb
CHANGED
@@ -51,7 +51,7 @@ class Grat::Content
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def template_url=(var)
|
54
|
-
super(var) unless var.empty?
|
54
|
+
super(var) unless var.nil? || var.empty?
|
55
55
|
end
|
56
56
|
|
57
57
|
def demo_string
|
@@ -75,9 +75,9 @@ class Grat::Content
|
|
75
75
|
while problem_var = detect_problem_var
|
76
76
|
counter += 1
|
77
77
|
return false if counter > 200
|
78
|
-
(detect_problem_var(problem_var => demo_string) ||
|
78
|
+
(detect_problem_var(problem_var => demo_string) ||
|
79
79
|
default_content_vars.merge!(problem_var => demo_string)) or
|
80
|
-
(detect_problem_var(problem_var => demo_array) ||
|
80
|
+
(detect_problem_var(problem_var => demo_array) ||
|
81
81
|
default_content_vars.merge!(problem_var => demo_string)) or
|
82
82
|
raise "Don't know how to reconcile."
|
83
83
|
end
|
data/lib/grat.rb
CHANGED
@@ -24,6 +24,57 @@ class Grat::Application < Sinatra::Base
|
|
24
24
|
haml :list
|
25
25
|
end
|
26
26
|
|
27
|
+
get '/admin/__export' do
|
28
|
+
content_type('text/json')
|
29
|
+
# Content-disposition: attachment; filename=fname.ext
|
30
|
+
response['Content-disposition'] = "attachment; filename=grat-export-at-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.json"
|
31
|
+
model.all.to_json
|
32
|
+
end
|
33
|
+
|
34
|
+
get '/admin/__import' do
|
35
|
+
haml :import_form
|
36
|
+
end
|
37
|
+
|
38
|
+
post '/admin/__import' do
|
39
|
+
json_text = file_import_text || params[:import][:text]
|
40
|
+
@import_results = import(json_text, params[:import][:strategy])
|
41
|
+
redirect '/admin/__all'
|
42
|
+
end
|
43
|
+
|
44
|
+
# Rather inefficient at present.
|
45
|
+
def import(json_text, strategy)
|
46
|
+
json_to_import = JSON.parse json_text
|
47
|
+
if json_to_import.is_a? Array
|
48
|
+
model.delete_all if strategy == 'demolish'
|
49
|
+
json_to_import.each do |record|
|
50
|
+
case strategy
|
51
|
+
when 'add'
|
52
|
+
import_record record
|
53
|
+
when 'replace'
|
54
|
+
import_record record, {:replace => true, :check=> true}
|
55
|
+
when 'demolish'
|
56
|
+
import_record record, {:replace => true, :check => false}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def import_record(hash, options = {:replace => false, :check => true})
|
63
|
+
record = model.find_by_url(hash['url']) if options[:check]
|
64
|
+
if record && options[:replace]
|
65
|
+
record.destroy if record
|
66
|
+
end
|
67
|
+
unless record && !options[:replace]
|
68
|
+
model.create hash
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def file_import_text
|
73
|
+
if params[:import] && params[:import][:file] && params[:import][:file][:tempfile]
|
74
|
+
params[:import][:file][:tempfile].read
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
27
78
|
get '/admin/*' do
|
28
79
|
haml :content_form
|
29
80
|
end
|
data/public/gratfiles/custom.css
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/* @override
|
2
2
|
http://localhost:9393/custom.css
|
3
3
|
http://grat.local/css/custom.css
|
4
|
+
http://localhost:9393/gratfiles/custom.css
|
4
5
|
*/
|
5
6
|
|
6
7
|
.grat_greet {
|
@@ -38,4 +39,15 @@ textarea {
|
|
38
39
|
p.editing {
|
39
40
|
min-height: 1em;
|
40
41
|
background-color: yellow;
|
41
|
-
}
|
42
|
+
}
|
43
|
+
|
44
|
+
input[type=file] {
|
45
|
+
padding-top: .5em;
|
46
|
+
font-size: 1.5em;
|
47
|
+
}
|
48
|
+
|
49
|
+
input[type=radio] {
|
50
|
+
width: 1em;
|
51
|
+
float: left;
|
52
|
+
margin-top: .25em;
|
53
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
.grat_greet
|
2
|
+
%p Hey, import some json if you like.
|
3
|
+
%form{:action => "/admin/__import", :method => 'post', :enctype=>'multipart/form-data' }
|
4
|
+
.import_file
|
5
|
+
%label{:for => 'import_file'} Upload a json file:
|
6
|
+
%input{:id => 'import_file', :type => 'file', :name => 'import[file]'}
|
7
|
+
%p
|
8
|
+
%em or
|
9
|
+
.import_text
|
10
|
+
%label{:for => 'import_text'} Paste some json here:
|
11
|
+
%textarea{:id => 'import_text', :name => 'import[text]'}
|
12
|
+
.import_replace_or_add
|
13
|
+
.add
|
14
|
+
%label{:for => 'import_add'} Add new records to database, ignore existing records.
|
15
|
+
%input{:type=> 'radio', :id => 'import_add', :value => 'add', :name => 'import[strategy]', :checked => 'checked'}
|
16
|
+
.replace
|
17
|
+
%label{:for => 'import_replace'} Add new and replace matching records. (danger!)
|
18
|
+
%input{:type=> 'radio', :id => 'import_replace', :value => 'replace', :name => 'import[strategy]'}
|
19
|
+
.demolish
|
20
|
+
%label{:for => 'import_demolish'} Demolish all existing records, then import. (omg danger!)
|
21
|
+
%input{:type=> 'radio', :id => 'import_demolish', :value => 'demolish', :name => 'import[strategy]'}
|
22
|
+
.submit
|
23
|
+
%input{:name => 'import[submit]', :type => 'submit', :value => "Let's save this thing"}
|
24
|
+
|
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.0.
|
4
|
+
version: 0.0.6
|
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-11-
|
12
|
+
date: 2009-11-09 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- views/css/_mod_skins.sass
|
119
119
|
- views/css/_template.sass
|
120
120
|
- views/css/_template_debug.sass
|
121
|
+
- views/import_form.haml
|
121
122
|
- views/layout.haml
|
122
123
|
- views/list.haml
|
123
124
|
- views/missing.haml
|