grat 0.0.8 → 0.1.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 CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  require 'rake'
4
4
  require 'echoe'
5
5
 
6
- Echoe.new('grat', '0.0.8') do |p|
6
+ Echoe.new('grat', '0.1.0') 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,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{grat}
5
- s.version = "0.0.8"
5
+ s.version = "0.1.0"
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"]
data/lib/grat/content.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  class Grat::Content
2
2
  include MongoMapper::Document
3
3
 
4
+ attr_accessor :suggested_fields
5
+
4
6
  key :url, String
5
7
  validates_uniqueness_of :url
6
8
  key :content, String
@@ -107,5 +109,7 @@ class Grat::Content
107
109
  send "#{render_engine}_render", y, content, locals
108
110
  end
109
111
 
110
-
112
+ def suggested_fields
113
+ @suggested_fields or []
114
+ end
111
115
  end
data/lib/grat/system.rb CHANGED
@@ -9,6 +9,17 @@ module Grat::System
9
9
  collection
10
10
  end
11
11
 
12
+ def request_type
13
+ case env['HTTP_ACCEPT']
14
+ when /html/
15
+ 'html'
16
+ when /json/
17
+ 'json'
18
+ when /xml/ #?
19
+ 'xml'
20
+ end
21
+ end
22
+
12
23
  not_found do
13
24
  missing_page
14
25
  end
@@ -18,7 +29,19 @@ module Grat::System
18
29
  end
19
30
 
20
31
  def content
21
- @content ||= model.find_by_url(url) || model.new(:url => url)
32
+ @content ||= model.find_by_url(url) || new_content
33
+ end
34
+
35
+ def new_content
36
+ content = model.new(:url => url)
37
+ if params[:template]
38
+ template = model.find_by_url params[:template]
39
+ if template
40
+ content.template_url = template.url
41
+ content.suggested_fields = template.default_content_vars.keys
42
+ end
43
+ end
44
+ content
22
45
  end
23
46
 
24
47
  def model
data/lib/grat.rb CHANGED
@@ -101,12 +101,19 @@ class Grat::Application < Sinatra::Base
101
101
 
102
102
  get '/*' do
103
103
  pass if content.new_record?
104
- locals = {}
105
- template_chain.inject('') do |sum, template|
106
- locals = template.default_content_vars.
107
- merge(template.attributes_for_variables).
108
- merge(locals)
109
- combine_docs(sum,template, locals)
104
+
105
+ case request_type
106
+ when 'html'
107
+ locals = {}
108
+ template_chain.inject('') do |sum, template|
109
+ locals = template.default_content_vars.
110
+ merge(template.attributes_for_variables).
111
+ merge(locals)
112
+ combine_docs(sum,template, locals)
113
+ end
114
+ when 'json'
115
+ response['Content-Type'] = 'application/json'
116
+ content.to_json
110
117
  end
111
118
  end
112
119
 
@@ -1,5 +1,22 @@
1
1
  // once page is loaded ...
2
2
  $(document).ready(function(){
3
+ $('.template select').change(function() {
4
+ // if template has url
5
+ selected_option = $(this).val()
6
+ if (selected_option) {
7
+ // look up template data
8
+ $.getJSON(selected_option, {ajax: 'true'}, function(j) {
9
+ // clear current suggested fields -- in future check for data first
10
+ $('#suggested_fields').html('');
11
+ for (key in j['default_content_vars']) {
12
+ new_field = '<div class="'+ key +'"><label for="content['+ key +']">'+ key +'</label><input name="content['+ key +']" /></div>';
13
+ $.test = new_field;
14
+ $('#suggested_fields').append(new_field);
15
+ }
16
+ })
17
+ }
18
+ })
19
+
3
20
  // New field button + features
4
21
  $('a[href=#new_field]').click(function(){
5
22
 
@@ -30,22 +47,22 @@ $(document).ready(function(){
30
47
  input.attr('name',new_name);
31
48
  })
32
49
 
33
- // Move to input field on enter
50
+ // Move to input field on enter
34
51
  editable.keypress(function(event){
35
-
36
- // move to field input is cancelled if enter is pressed
37
- if (event.which == 13) {
38
-
39
- // Remove editing class -- should add edited class maybe
40
- editable.removeClass('editing');
41
-
42
- // forward to text input
43
- $(editable).parent().children().filter('input').focus();
44
- return false
45
- } else {
46
- return event.which
47
- }
48
- });
52
+
53
+ // move to field input is cancelled if enter is pressed
54
+ if (event.which == 13) {
55
+
56
+ // Remove editing class -- should add edited class maybe
57
+ editable.removeClass('editing');
58
+
59
+ // forward to text input
60
+ $(editable).parent().children().filter('input').focus();
61
+ return false
62
+ } else {
63
+ return event.which
64
+ }
65
+ });
49
66
 
50
67
  editable.change(function() {
51
68
  console.log('blur');
@@ -33,6 +33,11 @@
33
33
  %div{:class => k}
34
34
  %label{:for => form_nest(k)}= k.capitalize
35
35
  %input{:name => form_nest(k), :value => v}
36
+ #suggested_fields
37
+ - content.suggested_fields.each do |field|
38
+ %div{:class => field}
39
+ %label{:for => form_nest(field)}= field.capitalize
40
+ %input{:name => form_nest(field)}
36
41
  #new_fields
37
42
  %p
38
43
  %a.add{:href=>'#new_field'} Add a New Field
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.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Schenkman-Moore