rid 0.5.2 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/LICENSE +1 -1
  2. data/README +14 -0
  3. data/Rakefile +18 -33
  4. data/VERSION +1 -0
  5. data/bin/rid +3 -6
  6. data/lib/rid/app.rb +49 -0
  7. data/lib/rid/attachments.rb +6 -2
  8. data/lib/rid/commands.rb +61 -39
  9. data/lib/rid/core_ext/hash.rb +1 -1
  10. data/lib/rid/database.rb +69 -0
  11. data/lib/rid/document.rb +99 -0
  12. data/lib/rid.rb +14 -41
  13. data/rid.gemspec +49 -78
  14. data/spec/mock_app/_database +1 -0
  15. data/spec/rid/app_spec.rb +59 -0
  16. data/spec/rid/attachments_spec.rb +2 -2
  17. data/spec/rid/commands_spec.rb +14 -0
  18. data/spec/rid/database_spec.rb +25 -0
  19. data/spec/rid/document_spec.rb +36 -0
  20. data/spec/spec_helper.rb +6 -0
  21. metadata +127 -86
  22. data/.gitmodules +0 -3
  23. data/README.rdoc +0 -92
  24. data/lib/rid/actions/base.rb +0 -15
  25. data/lib/rid/actions/pull.rb +0 -28
  26. data/lib/rid/actions/push.rb +0 -53
  27. data/lib/rid/actions/routes.rb +0 -44
  28. data/lib/rid/commands/destroy.rb +0 -9
  29. data/lib/rid/commands/generate.rb +0 -9
  30. data/lib/rid/commands/pull.rb +0 -4
  31. data/lib/rid/commands/push.rb +0 -4
  32. data/lib/rid/commands/routes.rb +0 -4
  33. data/lib/rid/design_document.rb +0 -149
  34. data/lib/rid/generators/application/USAGE +0 -10
  35. data/lib/rid/generators/application/application_generator.rb +0 -56
  36. data/lib/rid/generators/application/templates/README +0 -1
  37. data/lib/rid/generators/application/templates/_attachments/index.html +0 -11
  38. data/lib/rid/generators/application/templates/_attachments/stylesheets/application.css +0 -25
  39. data/lib/rid/generators/application/templates/_id +0 -1
  40. data/lib/rid/generators/application/templates/gitignore +0 -0
  41. data/lib/rid/generators/application/templates/lib/mustache.js +0 -305
  42. data/lib/rid/generators/application/templates/lib/path.js +0 -5
  43. data/lib/rid/generators/application/templates/lib/templates/layout.mustache +0 -14
  44. data/lib/rid/generators/application/templates/ridrc +0 -1
  45. data/lib/rid/generators/application/templates/validate_doc_update.js +0 -3
  46. data/lib/rid/generators/base.rb +0 -66
  47. data/lib/rid/generators/list/USAGE +0 -8
  48. data/lib/rid/generators/list/list_generator.rb +0 -10
  49. data/lib/rid/generators/list/templates/index.mustache +0 -23
  50. data/lib/rid/generators/list/templates/list.js +0 -34
  51. data/lib/rid/generators/named_base.rb +0 -22
  52. data/lib/rid/generators/scaffold/USAGE +0 -10
  53. data/lib/rid/generators/scaffold/scaffold_generator.rb +0 -32
  54. data/lib/rid/generators/show/USAGE +0 -8
  55. data/lib/rid/generators/show/show_generator.rb +0 -13
  56. data/lib/rid/generators/show/templates/delete.mustache +0 -20
  57. data/lib/rid/generators/show/templates/deleted.mustache +0 -3
  58. data/lib/rid/generators/show/templates/form.mustache +0 -22
  59. data/lib/rid/generators/show/templates/show.js +0 -48
  60. data/lib/rid/generators/show/templates/show.mustache +0 -13
  61. data/lib/rid/generators/update/USAGE +0 -8
  62. data/lib/rid/generators/update/templates/update.js +0 -48
  63. data/lib/rid/generators/update/update_generator.rb +0 -9
  64. data/lib/rid/generators/validation/USAGE +0 -9
  65. data/lib/rid/generators/validation/templates/validate_doc_update.js +0 -3
  66. data/lib/rid/generators/validation/validation_generator.rb +0 -34
  67. data/lib/rid/generators/view/USAGE +0 -8
  68. data/lib/rid/generators/view/templates/map.js +0 -5
  69. data/lib/rid/generators/view/view_generator.rb +0 -17
  70. data/lib/rid/generators.rb +0 -63
  71. data/lib/rid/makros.rb +0 -114
  72. data/lib/rid/version.rb +0 -3
  73. data/spec/rid/design_document_spec.rb +0 -220
  74. data/spec/rid/makros_spec.rb +0 -94
  75. data/spec/rid_spec.rb +0 -7
data/README.rdoc DELETED
@@ -1,92 +0,0 @@
1
- = Rid
2
- == Red in a different color
3
-
4
- Standalone Couchdb Application Development Suite
5
-
6
- With Rid you can easy build a standalone Couchdb application. Rid aims to bring some of the Rails beauty to Couchdb.
7
- Currently Rid supports Rails style Generators you will love, using the same awesome Thor library used in Rails 3.
8
-
9
-
10
- == Why?
11
-
12
- Why do we need a new Couchdb Application Development Suite? We already have the powerful {CouchApp}[http://github.com/couchapp/couchapp].
13
-
14
- I need more beauty. I want some elegance on the command line.
15
-
16
- I know my attempt is almost a small little step towards the beauty I aspire.
17
- I try to pilfer the most of now: From CouchApp and Ruby on Rails.
18
- So here we go:
19
-
20
- <em>Rid is designed to structure standalone Couchdb application development for maximum application portability.</em>
21
-
22
- === Web development that doesn't hurt
23
-
24
- Rid is a set of open-source tools that's optimized for programmer happiness and sustainable productivity. It lets you write beautyful code by favoring convention over configuration.
25
-
26
- === Write apps using just Javascript and HTML
27
-
28
- Render HTML documents using Javascript templates run by Couchdb. You'll get parallelism and cacheability, *using only HTML and Javascript*.
29
- Building standalone Couchdb applications according to correct principles affords you options not found on other platforms.
30
-
31
-
32
- == What comes next
33
-
34
- At the moment, Rid supports generating a scaffold application, pushing to a Couchdb server and pulling from a Couchdb.
35
- Rid injects the !code and !json makros introduced by CouchApp.
36
-
37
- The very next steps are:
38
-
39
- * add support for edit and delete
40
-
41
-
42
- == I need your help!
43
-
44
- The reason why I release that project in such an early state is that I beleave it's you, who invent that desired beauty!
45
-
46
-
47
- == Prerequisites
48
-
49
- All you need is Ruby and its packet manager RubyGems. If you do not have a Ruby environment,
50
-
51
- apt-get install ruby rubygems
52
-
53
- will probably install the required packages. If you run into any troubles, visit http://docs.rubygems.org/read/chapter/3 for in deapth installation notes for RubyGems, and http://www.ruby-lang.org/en/downloads/ for help on installing Ruby.
54
-
55
- Of course, Rid relies on Couchdb. You do not have to install your own Couchdb server if you have access to a Couchdb database over the internet, but I recommend it for development.
56
- If you are new to Couchdb, install it:
57
-
58
- apt-get install couchdb
59
-
60
- Take a look at the Couchdb Wiki, where the page http://wiki.apache.org/couchdb/Installation describes the installation for all common systems.
61
-
62
-
63
- == Installation
64
-
65
- Rid installation is easy.
66
- Rid is available as RubyGem, hosted on http://rubygems.org/ (aka Gemcutter) and Rubyforge (http://rubyforge.org).
67
- Install the gem with
68
-
69
- gem install rid
70
-
71
-
72
- == Gettings started
73
-
74
- Once installed, your system will have the brand new +rid+ command.
75
- So just type
76
-
77
- rid
78
-
79
- and relax.
80
-
81
-
82
- == Note on Patches/Pull Requests
83
-
84
- * Fork the project.
85
- * Make your feature addition or bug fix.
86
- * Commit, do not mess with rakefile, version, or history.
87
- * Send me a pull request. Bonus points for topic branches.
88
-
89
-
90
- == Copyright
91
-
92
- Copyright (c) 2010 Johannes Jörg Schmidt, TF. See LICENSE for details.
@@ -1,15 +0,0 @@
1
- require 'thor/group'
2
- require 'active_support/inflector'
3
-
4
- module Rid
5
- module Actions
6
- class Base < Thor::Group
7
- include Thor::Actions
8
-
9
- def self.banner
10
- "rid #{to_s.split('::').last.underscore}"
11
- end
12
- end
13
- end
14
- end
15
-
@@ -1,28 +0,0 @@
1
- require 'rid/actions/base'
2
- require 'rid/design_document'
3
-
4
- require "rest_client"
5
-
6
- module Rid
7
- module Actions
8
- class Pull < Base
9
- add_runtime_options!
10
-
11
- def pull
12
- doc = DesignDocument.new
13
- say "Pulling %s" % doc.url
14
-
15
- resp = RestClient.get doc.url(:attachments => true)
16
- doc.json = resp.body
17
-
18
- doc.write do |filename, content|
19
- create_file filename, content
20
- end
21
-
22
- say "Checked out %s" % doc.rev
23
- rescue RestClient::ResourceNotFound
24
- say "Error: Document %s does not exist!" % doc.id
25
- end
26
- end
27
- end
28
- end
@@ -1,53 +0,0 @@
1
- require 'rid/actions/base'
2
- require 'rid/design_document'
3
-
4
- require 'pathname'
5
- require "rest_client"
6
-
7
- module Rid
8
- module Actions
9
- class Push < Base
10
- def initialize(*args)
11
- super
12
- @doc = DesignDocument.new
13
- end
14
-
15
- def create_database_unless_exists
16
- RestClient.put @doc.database, nil
17
- say "Created database %s" % @doc.database
18
- rescue RestClient::PreconditionFailed
19
- end
20
-
21
- def push
22
- root = Pathname.new(destination_root)
23
- filenames = Dir[root.join "**/*"]
24
- filenames.map! { |file| Pathname.new file }
25
- filenames.map! { |path| path.relative_path_from root }
26
- filenames.delete_if { |path| !path.file? }
27
- filenames.map!(&:to_s)
28
- @doc.read(filenames) do |filename|
29
- File.read File.join(destination_root, filename)
30
- end
31
-
32
- say "Pushing to %s" % @doc.url
33
-
34
- resp = RestClient.put @doc.url, @doc.json
35
- response = JSON.parse(resp.body)
36
-
37
- if response["ok"]
38
- @doc.rev = response["rev"]
39
- File.open File.join(destination_root, "_rev"), "w" do |file|
40
- file << @doc.rev
41
- end
42
-
43
- say "Pushed %s" % @doc.rev
44
- else
45
- say "Error occured: %s" % response.inspect
46
- end
47
-
48
- rescue RestClient::Conflict
49
- say "Conflict! Try to pull first or delete ./_rev."
50
- end
51
- end
52
- end
53
- end
@@ -1,44 +0,0 @@
1
- require 'rid/actions/base'
2
-
3
- module Rid
4
- module Actions
5
- class Routes < Base
6
- def routes
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
9
-
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)]
14
- end
15
- end
16
-
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
26
- end
27
- end
28
-
29
- protected
30
-
31
- def attachment_url(file)
32
- File.join(Rid.database, '_design', File.basename(Rid.database), File.basename(file))
33
- end
34
-
35
- def list_url(view, list)
36
- File.join(Rid.database, '_design', File.basename(Rid.database), '_list', File.basename(view), File.basename(list, '.js'))
37
- end
38
-
39
- def show_url(show, id = '/')
40
- File.join(Rid.database, '_design', File.basename(Rid.database), '_show', File.basename(show, '.js'), id)
41
- end
42
- end
43
- end
44
- end
@@ -1,9 +0,0 @@
1
- require 'rid/generators'
2
-
3
- if [nil, "-h", "--help"].include?(ARGV.first)
4
- Rid::Generators.help 'destroy'
5
- exit
6
- end
7
-
8
- name = ARGV.shift
9
- Rid::Generators.invoke name, ARGV, :behavior => :revoke, :destination_root => Rid.root
@@ -1,9 +0,0 @@
1
- require 'rid/generators'
2
-
3
- if [nil, "-h", "--help"].include?(ARGV.first)
4
- Rid::Generators.help 'generate'
5
- exit
6
- end
7
-
8
- name = ARGV.shift
9
- Rid::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => Rid.root
@@ -1,4 +0,0 @@
1
- require 'rid'
2
- require 'rid/actions/pull'
3
-
4
- Rid::Actions::Pull.start ARGV, :destination_root => Rid.root
@@ -1,4 +0,0 @@
1
- require 'rid'
2
- require 'rid/actions/push'
3
-
4
- Rid::Actions::Push.start ARGV, :destination_root => Rid.root
@@ -1,4 +0,0 @@
1
- require 'rid'
2
- require 'rid/actions/routes'
3
-
4
- Rid::Actions::Routes.start ARGV, :destination_root => Rid.root
@@ -1,149 +0,0 @@
1
- require 'rid/core_ext/hash'
2
- require 'rid/attachments'
3
- require 'rid/makros'
4
-
5
- require 'uri'
6
-
7
- module Rid
8
- class DesignDocument
9
- # Files that should have a .js extension
10
- JAVASCRIPT_FILES = %w[
11
- validate_doc_update
12
- lists/*
13
- shows/*
14
- updates/*
15
- views/*/*
16
- ]
17
-
18
- # Files that should not be included in document
19
- EXCLUDE_FILES = %w[
20
- README
21
- ]
22
-
23
- include Attachments
24
- include Makros
25
-
26
- attr_accessor :hash
27
-
28
- def initialize
29
- @hash = {}
30
- end
31
-
32
- # Read document from a filesystem.
33
- #
34
- # Takes a filename,
35
- # many filenames,
36
- # or an array of filenames
37
- # and assign the return value of a yielded block to the hash.
38
- #
39
- # Nested hashes
40
- # like { "hash" => { "key" => "value" } }
41
- # can be constructed if the filename contains a slash (/),
42
- # eg "hash/key".
43
- #
44
- def read(*filenames, &block)
45
- filenames.flatten.uniq.each do |filename|
46
- # skip exclude files
47
- next if EXCLUDE_FILES.include?(filename)
48
-
49
- key = filename.dup
50
- # strip extname from javascript files
51
- key.sub!(/\.js$/, '') if filename =~ /#{JAVASCRIPT_FILES.join('|')}/
52
-
53
- hash.update_at key, block.call(filename)
54
- end
55
-
56
- map_attachments!
57
- inject_makros!
58
- end
59
-
60
- # Write document to a filesystem
61
- #
62
- # Takes a directoy as startpoint (default is nil),
63
- # a document hash (default is the design documents hash)
64
- # and recursively yields all keys and values to the given block.
65
- #
66
- # Nested hashes
67
- # like { "hash" => { "key" => "value" } }
68
- # will result in the yielded filename
69
- # "hash/key".
70
- #
71
- # The key "_attachments" has a special meaning:
72
- # the value holds base64 encoded data as well as other metadata.
73
- # This data will gets decoded and used as value for the key.
74
- #
75
- def write(&block)
76
- reduce_attachments!
77
- reject_makros!
78
-
79
- hash.flatten.each do |key, value|
80
- filename = key.dup
81
- # append extname to javascript files
82
- filename << '.js' if filename =~ /#{JAVASCRIPT_FILES.join('|')}/
83
-
84
- block.call(filename, value)
85
- end
86
- end
87
-
88
- # Returns a JSON string representation of the documents hash
89
- #
90
- def json
91
- hash.to_json
92
- end
93
-
94
- # Build the documents hash from a JSON string
95
- #
96
- def json=(json)
97
- self.hash = JSON.parse(json)
98
- end
99
-
100
-
101
- # Accessor for id
102
- def id
103
- hash["_id"] || Rid.id
104
- end
105
-
106
- # Accessor for rev
107
- def rev
108
- hash["_rev"] || Rid.rev
109
- end
110
-
111
- # Updates rev in documents hash
112
- def rev=(new_rev)
113
- hash["_rev"] = new_rev
114
- end
115
-
116
-
117
- # Accessor for rid database
118
- def database
119
- @database ||= Rid.database
120
- end
121
-
122
- # Base URL for document
123
- def base_url
124
- @base_url ||= File.join(database, id)
125
- end
126
-
127
- # URL for accessing design document
128
- #
129
- # Takes an optional options hash
130
- # which gets converted to url encoded options
131
- # and appended to the documents base url
132
- #
133
- def url(options = {})
134
- base_url + build_options_string(options)
135
- end
136
-
137
-
138
- private
139
-
140
- def build_options_string(options)
141
- return '' if options.empty?
142
- options_array = []
143
- options.each do |key, value|
144
- options_array << URI.escape([key, value].join('='))
145
- end
146
- '?' + options_array.join("&")
147
- end
148
- end
149
- end
@@ -1,10 +0,0 @@
1
- Description:
2
- The 'application' generator creates a new Rid application
3
- with a default directory structure and configuration
4
- at the path you specify.
5
-
6
- Example:
7
- rid generate application ~/rid/weblog
8
-
9
- This generates a skeletal Rid installation in ~/rid/weblog.
10
- See the README in the newly created application to get going.
@@ -1,56 +0,0 @@
1
- module Rid::Generators
2
- class ApplicationGenerator < Base
3
- argument :app_path, :type => :string
4
-
5
- def create_root
6
- self.destination_root = File.expand_path(app_path, destination_root)
7
-
8
- empty_directory '.'
9
- FileUtils.cd(destination_root) if File.directory?(destination_root)
10
- end
11
-
12
- def create_root_files
13
- template "ridrc", ".ridrc"
14
- copy_file "README"
15
- copy_file "gitignore", ".gitignore" unless options[:skip_git]
16
- template "_id"
17
- copy_file "validate_doc_update.js"
18
- empty_directory "lists"
19
- empty_directory "shows"
20
- empty_directory "updates"
21
- empty_directory "views"
22
- end
23
-
24
- def create_attachments_files
25
- empty_directory "_attachments"
26
- inside "_attachments" do
27
- empty_directory "images"
28
- empty_directory "javascripts"
29
- directory "stylesheets"
30
- template "index.html"
31
- end
32
- end
33
-
34
- def create_lib_files
35
- empty_directory "lib"
36
- inside "lib" do
37
- copy_file "mustache.js"
38
- copy_file "path.js"
39
- empty_directory "templates"
40
- inside "templates" do
41
- template "layout.mustache"
42
- end
43
- end
44
- end
45
-
46
- protected
47
-
48
- def app_name
49
- @app_name ||= File.basename(destination_root)
50
- end
51
-
52
- def app_title
53
- @app_title ||= app_name.humanize
54
- end
55
- end
56
- end
@@ -1 +0,0 @@
1
- # Welcome to Rid!
@@ -1,11 +0,0 @@
1
- <!DOCTYPE HTML>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html; charset=utf-8">
5
- <title><%= app_title %></title>
6
- <link rel="stylesheet" href="stylesheets/application.css" type="text/css" media="screen" charset="utf-8">
7
- </head>
8
- <body>
9
- <h1>Welcome to <%= app_title %>!</h1>
10
- </body>
11
- </html>
@@ -1,25 +0,0 @@
1
- body {
2
- background-color: #fff;
3
- color: #333;
4
- margin: 1cm 1.618cm;
5
- }
6
-
7
- body, p, ol, ul, td {
8
- font-family: verdana, arial, helvetica, sans-serif;
9
- font-size: 13px;
10
- line-height: 18px;
11
- }
12
-
13
- pre {
14
- background-color: #eee;
15
- padding: 10px;
16
- font-size: 11px;
17
- }
18
-
19
- a { color: #000; }
20
- a:visited { color: #666; }
21
- a:hover { color: #fff; background-color:#000; }
22
-
23
- .notice {
24
- color: green;
25
- }
@@ -1 +0,0 @@
1
- _design/<%= app_name %>
File without changes