rid 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,22 +4,25 @@ module Rid
4
4
  module Actions
5
5
  class Routes < Base
6
6
  def routes
7
- say 'Static:'
8
- Dir.glob(File.join(destination_root, "_attachments/*.html")).each do |file|
9
- say ' %s' % attachment_url(file)
10
- end
7
+ static_files = Dir.glob(File.join(destination_root, "_attachments/*.html"))
8
+ longest_name = (%w[show list] + static_files.map { |f| File.basename(f, '.html') }).map(&:length).sort.last + 1
11
9
 
12
- say 'Lists:'
13
- Dir.glob(File.join(destination_root, "lists/*")).each do |list|
14
- Dir.glob(File.join(destination_root, "views/*")).each do |view|
15
- say ' %s' % list_url(list, view)
10
+ unless static_files.empty?
11
+ say 'Static'
12
+ static_files.each do |file|
13
+ say ' %s %s' % [(File.basename(file, '.html') + ":").ljust(longest_name), attachment_url(file)]
16
14
  end
17
15
  end
18
16
 
19
- say 'Shows:'
20
- Dir.glob(File.join(destination_root, "shows/*")).each do |show|
21
- say ' %s' % show_url(show)
22
- say ' %s' % show_url(show, '/:id')
17
+ Dir.glob(File.join(destination_root, "views/*")).each do |model|
18
+ model_name = File.basename(model).singularize
19
+ say model_name.humanize
20
+ Dir.glob(File.join(destination_root, "shows/#{model_name}*")).each do |show|
21
+ say ' %s %s' % ["show:".ljust(longest_name), show_url(show, '/:id')]
22
+ end
23
+ Dir.glob(File.join(destination_root, "views/#{model_name}*")).each do |view|
24
+ say ' %s %s' % ["list:".ljust(longest_name), list_url(view, model)]
25
+ end
23
26
  end
24
27
  end
25
28
 
@@ -29,7 +32,7 @@ module Rid
29
32
  File.join(Rid.database, '_design', File.basename(Rid.database), File.basename(file))
30
33
  end
31
34
 
32
- def list_url(list, view)
35
+ def list_url(view, list)
33
36
  File.join(Rid.database, '_design', File.basename(Rid.database), '_list', File.basename(view), File.basename(list, '.js'))
34
37
  end
35
38
 
@@ -34,7 +34,11 @@ module Rid::Generators
34
34
  def create_lib_files
35
35
  empty_directory "lib"
36
36
  inside "lib" do
37
- copy_file "mustache.js"
37
+ copy_file "mustache.js"
38
+ empty_directory "templates"
39
+ inside "templates" do
40
+ template "layout.mustache"
41
+ end
38
42
  end
39
43
  end
40
44
 
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE HTML>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
5
+ <title><%= app_title %>: {{title}}</title>
6
+ <link rel="stylesheet" href="../../stylesheets/application.css" type="text/css" media="screen" charset="utf-8">
7
+ </head>
8
+ <body>
9
+ <h1><%= app_title %></h1>
10
+ <h2>{{title}}</h2>
11
+ {{>body}}
12
+ </body>
13
+ </html>
@@ -2,8 +2,9 @@ require 'rid/generators/named_base'
2
2
 
3
3
  module Rid::Generators
4
4
  class ListGenerator < NamedBase
5
- def create_list_function
5
+ def create_templates
6
6
  template "list.js", "lists/#{pluralized_model_name}.js"
7
+ template "index.mustache", "lib/templates/#{pluralized_model_name}/index.mustache"
7
8
  end
8
9
  end
9
10
  end
@@ -0,0 +1,16 @@
1
+ <table>
2
+ <tr>
3
+ <% attributes.each do |attribute| -%>
4
+ <th><%= attribute.humanize %></th>
5
+ <% end -%>
6
+ <th></th>
7
+ </tr>
8
+ {{#rows}}
9
+ <tr>
10
+ <% attributes.each do |attribute| -%>
11
+ <td>{{<%= attribute %>}}</td>
12
+ <% end -%>
13
+ <td><a href="../../_show/<%= model_name %>/{{id}}">Show <%= model_name.humanize %></a></td>
14
+ </tr>
15
+ {{/rows}}
16
+ </table>
@@ -1,29 +1,31 @@
1
1
  function(head, req) {
2
- provides("html", function() {
3
- var header = '<html><head><link rel="stylesheet" href="../../stylesheets/application.css" type="text/css" media="screen" charset="utf-8"></head><body><h1>Listing <%= pluralized_model_name.humanize %></h1>';
4
-
5
- header += '<p><a href="../../_show/<%= model_name %>/">New <%= model_name.humanize %></a></p>';
2
+ // !code mustache.js
3
+ // !json templates/layout.mustache
4
+ // !json templates/<%= pluralized_model_name %>/index.mustache
6
5
 
7
- header += '<table><tr>';
6
+ provides("html", function() {
7
+ var view = {
8
+ title: "Listing <%= pluralized_model_name.humanize %>",
9
+ body: {
10
+ rows: function() {
11
+ var rows = [];
12
+ var row;
13
+ while (row = getRow()) {
14
+ rows.push({
8
15
  <% attributes.each do |attribute| -%>
9
- header += '<th><%= attribute.humanize %></th>';
16
+ <%= attribute %>: row.value['<%= attribute %>'],
10
17
  <% end -%>
11
- header += '<th></th>';
12
- header += '</tr>';
13
- send(header);
18
+ id: row.id
19
+ });
20
+ }
14
21
 
15
- var row;
16
- while (row = getRow()) {
17
- var body = '<tr>';
18
- <% attributes.each do |attribute| -%>
19
- body += '<td>' + row.value['<%= attribute %>'] + '</td>';
20
- <% end -%>
21
- body += '<td><a href="../../_show/<%= model_name %>/' + row.id + '" alt="Show <%= model_name.humanize %>">Show</a></td>';
22
- body += '</tr>';
23
- send(body);
24
- }
22
+ return rows;
23
+ }
24
+ }
25
+ };
25
26
 
26
- var tail = '</table></body></html>';
27
- return tail;
27
+ Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>.index }, function(line) {
28
+ send(line + "\n");
29
+ });
28
30
  });
29
31
  }
@@ -4,6 +4,7 @@ module Rid::Generators
4
4
  class ShowGenerator < NamedBase
5
5
  def create_show_function
6
6
  template "show.js", "shows/#{model_name}.js"
7
+ template "show.mustache", "lib/templates/#{pluralized_model_name}/show.mustache"
7
8
  end
8
9
  end
9
10
  end
@@ -1,20 +1,22 @@
1
1
  function(doc, req) {
2
- var head = '<html><head><link rel="stylesheet" href="../../stylesheets/application.css" type="text/css" media="screen" charset="utf-8"></head><body>';
3
- var body = '';
4
- var tail = '</body></html>';
2
+ // !code mustache.js
3
+ // !json templates/layout.mustache
4
+ // !json templates/<%= pluralized_model_name %>/show.mustache
5
+
5
6
  if(doc) {
6
- body += '<p><a href="../../_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">List <%= pluralized_model_name.humanize %></a></p>';
7
- <% attributes.each do |attribute| -%>
8
- if(doc['<%= attribute %>']) {
9
- body += '<p><strong><%= attribute.humanize %></strong>: ' + doc['<%= attribute %>'] + '</p>';
10
- }
11
- <% end -%>
12
- return head + '<h1>Showing <%= model_name.humanize %></h1>' + body + tail;
7
+ provides("html", function() {
8
+ var view = {
9
+ title: "Showing <%= model_name.humanize %>",
10
+ body: {
11
+ title: doc.title,
12
+ body: doc.body,
13
+ id: doc._id
14
+ }
15
+ };
16
+
17
+ return Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>.show });
18
+ });
13
19
  } else {
14
- <% attributes.each do |attribute| -%>
15
- body += '<p><label><%= attribute.humanize %></label>: <input type="text" name="<%= model_name %>[<%= attribute %>]" id="<%= model_name %>_<%= attribute %>" /></p>';
16
- <% end -%>
17
- body += '<p><input type="submit" /> <a href="../../_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">Cancel</a></p>';
18
- return head + '<h1>New <%= model_name.humanize %></h1>' + body + tail;
20
+ return '404 not found';
19
21
  }
20
22
  }
@@ -0,0 +1,7 @@
1
+ <p><a href="../../_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">List <%= pluralized_model_name.humanize %></a></p>
2
+ <dl>
3
+ <% attributes.each do |attribute| -%>
4
+ <dt><%= attribute.humanize %></dt>
5
+ <dd>{{<%= attribute %>}}</dd>
6
+ <% end -%>
7
+ </dl>
data/lib/rid/makros.rb CHANGED
@@ -50,8 +50,24 @@ module Rid
50
50
 
51
51
 
52
52
  # builds a javascript variable assignment line for filename with value
53
+ # 'var %s = %s;' % [filename.split(/[\.\/]/).join('_'), value.to_json]
53
54
  def expand_json_makro(filename, value)
54
- 'var %s = %s;' % [filename.split(/[\.\/]/).join('_'), value.to_json]
55
+ name = filename.sub(/\..*$/, '')
56
+ parts = name.split('/')
57
+
58
+ if parts.size > 1
59
+ var = "var #{parts.first};"
60
+ 0.upto(parts.size - 2) do |i|
61
+ v = parts[0..i].join('.')
62
+ var << " if (!#{v}) #{v} = {};"
63
+ end
64
+ var << "\n"
65
+ var << "#{parts.join('.')} = %s;"
66
+ else
67
+ var = "var #{name} = %s;"
68
+ end
69
+
70
+ var % value.to_json
55
71
  end
56
72
 
57
73
  # injects a makro and yields block with the filenames for found makros
data/lib/rid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rid
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/rid.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rid}
8
- s.version = "0.3.1"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Johannes J. Schmidt"]
12
- s.date = %q{2010-03-12}
12
+ s.date = %q{2010-03-13}
13
13
  s.default_executable = %q{rid}
14
14
  s.description = %q{With Couch you can easy build a standalone CouchDB application. Couch aims to bring some of the Rails beauty to CouchDB. Currently Couch supports Rails style Generators you will love, using the same awesome Thor library used in Rails3.}
15
15
  s.email = %q{schmidt@netzmerk.com}
@@ -48,11 +48,13 @@ Gem::Specification.new do |s|
48
48
  "lib/rid/generators/application/templates/_id",
49
49
  "lib/rid/generators/application/templates/gitignore",
50
50
  "lib/rid/generators/application/templates/lib/mustache.js",
51
+ "lib/rid/generators/application/templates/lib/templates/layout.mustache",
51
52
  "lib/rid/generators/application/templates/ridrc",
52
53
  "lib/rid/generators/application/templates/validate_doc_update.js",
53
54
  "lib/rid/generators/base.rb",
54
55
  "lib/rid/generators/list/USAGE",
55
56
  "lib/rid/generators/list/list_generator.rb",
57
+ "lib/rid/generators/list/templates/index.mustache",
56
58
  "lib/rid/generators/list/templates/list.js",
57
59
  "lib/rid/generators/named_base.rb",
58
60
  "lib/rid/generators/scaffold/USAGE",
@@ -60,6 +62,7 @@ Gem::Specification.new do |s|
60
62
  "lib/rid/generators/show/USAGE",
61
63
  "lib/rid/generators/show/show_generator.rb",
62
64
  "lib/rid/generators/show/templates/show.js",
65
+ "lib/rid/generators/show/templates/show.mustache",
63
66
  "lib/rid/generators/validation/USAGE",
64
67
  "lib/rid/generators/validation/templates/validate_doc_update.js",
65
68
  "lib/rid/generators/validation/validation_generator.rb",
@@ -31,19 +31,19 @@ describe "Makros" do
31
31
  it "should expand json" do
32
32
  @doc.hash = { "hash" => { "key" => "// !json json.json" }, "lib" => { "json.json" => "value" } }
33
33
  @doc.inject_makros!
34
- @doc.hash["hash"]["key"].should == 'var json_json = "value";'
34
+ @doc.hash["hash"]["key"].should == 'var json = "value";'
35
35
  end
36
36
 
37
37
  it "should not remove code that follows" do
38
38
  @doc.hash = { "hash" => { "key" => "// !json json.json\nvalue" }, "lib" => { "json.json" => "value" } }
39
39
  @doc.inject_makros!
40
- @doc.hash["hash"]["key"].should == "var json_json = \"value\";\nvalue"
40
+ @doc.hash["hash"]["key"].should == "var json = \"value\";\nvalue"
41
41
  end
42
42
 
43
43
  it "should store injection" do
44
44
  @doc.hash = { "hash" => { "key" => "// !json json.json" }, "lib" => { "json.json" => "value" } }
45
45
  @doc.inject_makros!
46
- @doc.hash["injections"].should == [{ "makro" => "json", "target" => "hash/key", "lib" => "json.json", "start" => 0, "size" => 24 }]
46
+ @doc.hash["injections"].should == [{ "makro" => "json", "target" => "hash/key", "lib" => "json.json", "start" => 0, "size" => 19 }]
47
47
  end
48
48
  end
49
49
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- - 1
9
- version: 0.3.1
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Johannes J. Schmidt
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-12 00:00:00 +01:00
17
+ date: 2010-03-13 00:00:00 +01:00
18
18
  default_executable: rid
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -127,11 +127,13 @@ files:
127
127
  - lib/rid/generators/application/templates/_id
128
128
  - lib/rid/generators/application/templates/gitignore
129
129
  - lib/rid/generators/application/templates/lib/mustache.js
130
+ - lib/rid/generators/application/templates/lib/templates/layout.mustache
130
131
  - lib/rid/generators/application/templates/ridrc
131
132
  - lib/rid/generators/application/templates/validate_doc_update.js
132
133
  - lib/rid/generators/base.rb
133
134
  - lib/rid/generators/list/USAGE
134
135
  - lib/rid/generators/list/list_generator.rb
136
+ - lib/rid/generators/list/templates/index.mustache
135
137
  - lib/rid/generators/list/templates/list.js
136
138
  - lib/rid/generators/named_base.rb
137
139
  - lib/rid/generators/scaffold/USAGE
@@ -139,6 +141,7 @@ files:
139
141
  - lib/rid/generators/show/USAGE
140
142
  - lib/rid/generators/show/show_generator.rb
141
143
  - lib/rid/generators/show/templates/show.js
144
+ - lib/rid/generators/show/templates/show.mustache
142
145
  - lib/rid/generators/validation/USAGE
143
146
  - lib/rid/generators/validation/templates/validate_doc_update.js
144
147
  - lib/rid/generators/validation/validation_generator.rb