grat 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -5,6 +5,7 @@ config.ru
5
5
  lib/environment.rb
6
6
  lib/grat.rb
7
7
  lib/grat/content.rb
8
+ lib/grat/hash_binding.rb
8
9
  lib/grat/mongomapper_patches.rb
9
10
  lib/grat/system.rb
10
11
  public/gratfiles/application.js
data/Rakefile CHANGED
@@ -3,9 +3,9 @@ require 'rubygems'
3
3
  require 'rake'
4
4
  require 'echoe'
5
5
 
6
- Echoe.new('grat', '0.0.4') do |p|
6
+ Echoe.new('grat', '0.0.5') do |p|
7
7
  p.summary = "Minimal CMS for Rack and MongoDB."
8
- p.description = "Basic interface for making webpages with Haml and (later) erb. Supports nested templates."
8
+ p.description = "Basic interface for making webpages with Haml and Erb. Supports nested templates."
9
9
  p.url = "http://samsm.com/"
10
10
  p.author = "Sam Schenkman-Moore"
11
11
  p.email = "samsm@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.4"
5
+ s.version = "0.0.5"
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-02}
10
- s.description = %q{Basic interface for making webpages with Haml and (later) erb. Supports nested templates.}
9
+ s.date = %q{2009-11-03}
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
- s.extra_rdoc_files = ["README", "lib/environment.rb", "lib/grat.rb", "lib/grat/content.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/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"]
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"]
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
@@ -41,3 +41,4 @@ module Grat
41
41
  end
42
42
 
43
43
  require Grat.lib_path + '/grat/system'
44
+ require Grat.lib_path + '/grat/hash_binding'
data/lib/grat/content.rb CHANGED
@@ -6,14 +6,11 @@ class Grat::Content
6
6
  key :content, String
7
7
  key :tags, Array
8
8
  key :template_url, String
9
- key :variables_needed, Array
10
9
  timestamps!
11
10
 
12
11
  before_save :detect_default_content_vars
13
12
  key :default_content_vars, Hash
14
-
15
- key :render_engine_name, String
16
-
13
+
17
14
  def editable_fields
18
15
  attributes.reject {|k,v| uneditable_keys.include? k }
19
16
  end
@@ -62,13 +59,20 @@ class Grat::Content
62
59
  end
63
60
 
64
61
  def render_engine
65
- @render_engine ||= case render_engine_name
66
- when 'haml',nil # the default for now
67
- require 'haml'
68
- Haml::Engine.new(content)
69
- when 'erb'
70
- raise 'Unimplemented!'
62
+ if content.match(/\A[!%#.=-]/)
63
+ :haml
64
+ else
65
+ :erb
71
66
  end
67
+ #
68
+ #
69
+ # @render_engine ||= case render_engine_name
70
+ # when 'haml',nil # the default for now
71
+ # require 'haml'
72
+ # Haml::Engine.new(content)
73
+ # when 'erb'
74
+ # raise 'Unimplemented!'
75
+ # end
72
76
  end
73
77
 
74
78
  def detect_default_content_vars
@@ -84,6 +88,17 @@ class Grat::Content
84
88
  end
85
89
  end
86
90
 
91
+ def haml_render(text, template, vars)
92
+ require 'haml'
93
+ haml_template = Haml::Engine.new(template)
94
+ haml_template.render(haml_template, vars) { text }
95
+ end
96
+
97
+ def erb_render(text, template, vars)
98
+ require 'erb'
99
+ ERB.new(template,0).result(Grat::HashBinding.new(vars).get_binding { text })
100
+ end
101
+
87
102
  def detect_problem_var(resolution = {})
88
103
  begin
89
104
  rendered = content_with(default_content_vars.merge(resolution), problem_var = nil)
@@ -94,7 +109,7 @@ class Grat::Content
94
109
  end
95
110
 
96
111
  def content_with(locals = {},y = '')
97
- render_engine.render(render_engine,locals) { y }
112
+ send "#{render_engine}_render", y, content, locals
98
113
  end
99
114
 
100
115
 
@@ -0,0 +1,18 @@
1
+ # A class to assist in turning a hash into a binding (for erb rendering)
2
+ class Grat::HashBinding
3
+
4
+ attr_accessor :hash
5
+
6
+ def initialize(hsh)
7
+ self.hash = hsh
8
+ end
9
+
10
+ def get_binding
11
+ binding
12
+ end
13
+
14
+ def method_missing(meth,*args)
15
+ hash[meth]
16
+ end
17
+
18
+ end
data/lib/grat.rb CHANGED
@@ -38,12 +38,18 @@ class Grat::Application < Sinatra::Base
38
38
  locals = {}
39
39
  template_chain.inject('') do |sum, template|
40
40
  locals.merge!(template.default_content_vars.merge(template.attributes))
41
- require 'haml'
42
- haml_template = Haml::Engine.new(template.content)
43
- result = haml_template.render(haml_template, locals) { sum }
41
+
42
+ combine_docs(sum,template, locals)
43
+ # require 'haml'
44
+ # haml_template = Haml::Engine.new(template.content)
45
+ # result = haml_template.render(haml_template, locals) { sum }
44
46
  end
45
47
  end
46
48
 
49
+ def combine_docs(text,template,vars)
50
+ template.content_with(vars,text)
51
+ end
52
+
47
53
  def haml(*args)
48
54
  require 'haml'
49
55
  super(*args)
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
4
+ version: 0.0.5
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-02 00:00:00 -05:00
12
+ date: 2009-11-03 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,7 +52,7 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: "0"
54
54
  version:
55
- description: Basic interface for making webpages with Haml and (later) erb. Supports nested templates.
55
+ description: Basic interface for making webpages with Haml and Erb. Supports nested templates.
56
56
  email: samsm@samsm.com
57
57
  executables: []
58
58
 
@@ -63,6 +63,7 @@ extra_rdoc_files:
63
63
  - lib/environment.rb
64
64
  - lib/grat.rb
65
65
  - lib/grat/content.rb
66
+ - lib/grat/hash_binding.rb
66
67
  - lib/grat/mongomapper_patches.rb
67
68
  - lib/grat/system.rb
68
69
  files:
@@ -73,6 +74,7 @@ files:
73
74
  - lib/environment.rb
74
75
  - lib/grat.rb
75
76
  - lib/grat/content.rb
77
+ - lib/grat/hash_binding.rb
76
78
  - lib/grat/mongomapper_patches.rb
77
79
  - lib/grat/system.rb
78
80
  - public/gratfiles/application.js