Capcode 0.8.7 → 0.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/README.rdoc +10 -1
  2. data/doc/rdoc/classes/Capcode.html +410 -390
  3. data/doc/rdoc/classes/Capcode/Helpers.html +146 -126
  4. data/doc/rdoc/created.rid +1 -1
  5. data/doc/rdoc/files/README_rdoc.html +26 -2
  6. data/doc/rdoc/files/lib/capcode/render/haml_rb.html +1 -1
  7. data/doc/rdoc/files/lib/capcode/render/json_rb.html +1 -1
  8. data/doc/rdoc/files/lib/capcode/render/markaby_rb.html +1 -1
  9. data/doc/rdoc/files/lib/capcode/render/sass_rb.html +1 -1
  10. data/doc/rdoc/files/lib/capcode/render/webdav_rb.html +1 -1
  11. data/doc/rdoc/files/lib/capcode_rb.html +1 -1
  12. data/doc/rdoc/fr_file_index.html +5 -0
  13. data/examples/blog-ar.rb +81 -0
  14. data/examples/blog-ar.yml +3 -0
  15. data/examples/blog-sq.rb +82 -0
  16. data/examples/blog-sq.yml +3 -0
  17. data/examples/mail/mail_html.rhtml +1 -0
  18. data/examples/mail/mail_text.rhtml +1 -0
  19. data/examples/mail/ok.rhtml +1 -0
  20. data/examples/mail/rubyfr.png +0 -0
  21. data/examples/mustache/with_class.mustache +8 -0
  22. data/examples/mustache/without_class.mustache +1 -0
  23. data/examples/render-binary.rb +46 -0
  24. data/examples/render-email.rb +68 -0
  25. data/examples/render-erb.rb +2 -0
  26. data/examples/render-mustache.rb +30 -0
  27. data/examples/render-redirect.rb +19 -0
  28. data/lib/capcode.rb +3 -0
  29. data/lib/capcode/base/ar.rb +54 -0
  30. data/lib/capcode/base/couchdb.rb +5 -1
  31. data/lib/capcode/base/dm.rb +5 -1
  32. data/lib/capcode/base/sq.rb +58 -0
  33. data/lib/capcode/core_ext.rb +1 -1
  34. data/lib/capcode/render/binary.rb +8 -0
  35. data/lib/capcode/render/email.rb +73 -0
  36. data/lib/capcode/render/haml.rb +5 -1
  37. data/lib/capcode/render/json.rb +5 -1
  38. data/lib/capcode/render/markaby.rb +5 -1
  39. data/lib/capcode/render/mustache.rb +37 -0
  40. data/lib/capcode/render/none.rb +7 -0
  41. data/lib/capcode/render/redirect.rb +7 -0
  42. data/lib/capcode/render/sass.rb +5 -1
  43. data/lib/capcode/render/webdav.rb +11 -7
  44. data/lib/capcode/version.rb +1 -1
  45. metadata +30 -3
  46. data/examples/my_blog.db +0 -0
@@ -1,5 +1,9 @@
1
1
  require 'rubygems'
2
- require 'couch_foo'
2
+ begin
3
+ require 'couch_foo'
4
+ rescue LoadError => e
5
+ raise MissingLibrary, "CouchFoo could not be loaded (is it installed?): #{e.message}"
6
+ end
3
7
  require 'yaml'
4
8
  require 'logger'
5
9
 
@@ -1,5 +1,9 @@
1
1
  require 'rubygems'
2
- require 'dm-core'
2
+ begin
3
+ require 'dm-core'
4
+ rescue LoadError => e
5
+ raise MissingLibrary, "DataMapper could not be loaded (is it installed?): #{e.message}"
6
+ end
3
7
  require 'yaml'
4
8
  require 'logger'
5
9
 
@@ -0,0 +1,58 @@
1
+ begin
2
+ require 'sequel'
3
+ Sequel.extension :migration
4
+ Sequel.extension :inflector
5
+ rescue LoadError => e
6
+ raise LoadError, "Sequel could not be loaded (is it installed?): #{e.message}"
7
+ end
8
+
9
+ module Capcode
10
+ # This module contains the resources needed in a model
11
+ module Resource
12
+ end
13
+
14
+ # This class allow you to define models
15
+ class Base
16
+ def self.method_missing( name, *args, &block )
17
+ if block_given?
18
+ Capcode::db[self.to_s.tableize.to_sym].__send__(name.to_sym, *args, &block)
19
+ else
20
+ Capcode::db[self.to_s.tableize.to_sym].__send__(name.to_sym, *args)
21
+ end
22
+ end
23
+ end
24
+
25
+ class << self
26
+ # This class allow you to define models
27
+ def Model( n )
28
+ @final = [n, @final.to_f].max
29
+ m = (@migrations ||= [])
30
+ Class.new(Sequel::Migration) do
31
+ meta_def(:version) { n }
32
+ meta_def(:inherited) { |k| m << k }
33
+ end
34
+ end
35
+
36
+ def db
37
+ @db ||= Sequel.connect(@dbconfig)
38
+ end
39
+
40
+ def db_connect( dbfile, logfile )
41
+ @dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
42
+ @dbconfig[:adapter] = "sqlite" if @dbconfig[:adapter] == "sqlite3"
43
+ version = dbconfig.delete(:schema_version) { |_| @final }
44
+
45
+ if @migrations
46
+ Capcode::db.create_table? :schema_table do
47
+ Float :version
48
+ end
49
+ si = Capcode::db[:schema_table].first || (Capcode::db[:schema_table].insert(:version => 0); {:version => 0})
50
+ @migrations.each do |k|
51
+ k.apply(Capcode::db, :up) if si[:version] < k.version and k.version <= version
52
+ k.apply(Capcode::db, :down) if si[:version] >= k.version and k.version > version
53
+ end
54
+ Capcode::db[:schema_table].where(:version => si[:version]).update(:version => version)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -15,7 +15,7 @@ class Regexp
15
15
  end
16
16
 
17
17
  class Hash
18
- def keys_to_sym
18
+ def keys_to_sym #:nodoc:
19
19
  self.each do |k, v|
20
20
  self.delete(k)
21
21
  self[k.to_s.to_sym] = v
@@ -0,0 +1,8 @@
1
+ module Capcode
2
+ module Helpers
3
+ def render_binary( f, opts ) #:nodoc:
4
+ @response['Content-Type'] = opts[:content_type]||opts['Content-Type']||"binary/octet-stream"
5
+ self.send(f)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,73 @@
1
+ begin
2
+ require 'mail'
3
+ rescue LoadError => e
4
+ raise MissingLibrary, "mail could not be loaded (is it installed?): #{e.message}"
5
+ end
6
+
7
+ module Capcode
8
+ module Helpers
9
+ def render_email( f, _ ) #:nodoc:
10
+ if @smtp.nil?
11
+ @smtp = { :server => "127.0.0.1", :port => 25 }.merge(Capcode.get( :smtp ) || {})
12
+ end
13
+
14
+ # Set SMTP info
15
+ conf = Mail::Configuration.instance.defaults
16
+ conf.smtp @smtp[:server], @smtp[:port]
17
+
18
+ # Create mail
19
+ mail = Mail.new()
20
+
21
+ # Mail Header
22
+ mail.from = f[:from]
23
+ mail.subject = f[:subject] if f.has_key?(:subject)
24
+ [:to, :cc, :bcc].each do |t|
25
+ next unless f.has_key?(t) and not f[t].nil?
26
+ if f[t].class == Array
27
+ mail[t] = f[t]
28
+ else
29
+ mail[t] = f[t].to_s.split( ',' ).map { |x| x.strip }
30
+ end
31
+ end
32
+ mail.message_id = f[:message_id] if f.has_key?(:message_id)
33
+
34
+ # Mail Body
35
+ if f[:body].class == String
36
+ mail.body = f[:body]
37
+ elsif f[:body].class == Hash
38
+ if f[:body].has_key?(:html)
39
+ mail.html_part = Mail::Part.new
40
+ mail.html_part.content_type = f[:body][:html].delete(:content_type) { |_| 'text/html' }
41
+ mail.html_part.body = render( f[:body][:html] )
42
+ end
43
+ if f[:body].has_key?(:text)
44
+ mail.text_part = Mail::Part.new
45
+ mail.text_part.body = render( f[:body][:text] )
46
+ end
47
+ end
48
+
49
+ # Mail Attachment
50
+ if f.has_key?(:file)
51
+ f[:file] = [f[:file]] unless f[:file].class == Array
52
+ f[:file].each do |file|
53
+ data = {}
54
+ if file.class == Hash
55
+ data[:filename] = file.delete(:filename) if file.has_key?(:filename)
56
+ data[:mime_type] = file.delete(:mime_type) if file.has_key?(:mime_type)
57
+ data[:data] = self.send(file[:data])
58
+ else
59
+ data = { :data => render( :static => file, :exact_path => false ), :filename => File.basename(file) }
60
+ end
61
+ mail.add_file(data)
62
+ end
63
+ end
64
+
65
+ begin
66
+ mail.deliver!
67
+ render f[:ok]
68
+ rescue
69
+ render f[:error]
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,4 +1,8 @@
1
- require "haml"
1
+ begin
2
+ require 'haml'
3
+ rescue LoadError => e
4
+ raise MissingLibrary, "Haml could not be loaded (is it installed?): #{e.message}"
5
+ end
2
6
 
3
7
  module Capcode
4
8
  module Helpers
@@ -1,4 +1,8 @@
1
- require 'json'
1
+ begin
2
+ require 'json'
3
+ rescue LoadError => e
4
+ raise MissingLibrary, "Json could not be loaded (is it installed?): #{e.message}"
5
+ end
2
6
 
3
7
  module Capcode
4
8
  module Helpers
@@ -1,4 +1,8 @@
1
- require "markaby"
1
+ begin
2
+ require 'markaby'
3
+ rescue LoadError => e
4
+ raise MissingLibrary, "Markaby could not be loaded (is it installed?): #{e.message}"
5
+ end
2
6
 
3
7
  Markaby::Builder.set(:indent, 2)
4
8
 
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'mustache'
3
+ rescue LoadError => e
4
+ raise MissingLibrary, "Mustache could not be loaded (is it installed?): #{e.message}"
5
+ end
6
+
7
+ module Capcode
8
+ module Helpers
9
+ def render_mustache( f, opts ) #:nodoc:
10
+ mustache_path = Capcode.get( :mustache ) || Capcode.static()
11
+
12
+ name = Mustache.classify(f.to_s)
13
+
14
+ if Capcode::Views.const_defined?(name)
15
+ klass = Capcode::Views.const_get(name)
16
+ else
17
+ klass = Mustache
18
+ klass.template_file = mustache_path + "/" + f.to_s + ".mustache"
19
+ end
20
+
21
+ klass.template_extension = 'mustache'
22
+ klass.template_path = mustache_path
23
+
24
+ instance = klass.new
25
+
26
+ instance_variables.each do |name|
27
+ instance.instance_variable_set(name, instance_variable_get(name))
28
+ end
29
+
30
+ opts.each do |k, v|
31
+ instance[k] = v
32
+ end
33
+
34
+ instance.to_html
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Capcode
2
+ module Helpers
3
+ def render_none( f = "", _ ) #:nodoc:
4
+ return [204, {}, f]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Capcode
2
+ module Helpers
3
+ def render_redirect( f, _ ) #:nodoc:
4
+ redirect(f)
5
+ end
6
+ end
7
+ end
@@ -1,4 +1,8 @@
1
- require "sass"
1
+ begin
2
+ require 'sass'
3
+ rescue LoadError => e
4
+ raise MissingLibrary, "Sass could not be loaded (is it installed?): #{e.message}"
5
+ end
2
6
 
3
7
  module Capcode
4
8
  module Helpers
@@ -4,13 +4,17 @@ require 'time'
4
4
  require 'uri'
5
5
  require 'rexml/document'
6
6
  require 'webrick/httputils'
7
-
8
- require 'rack_dav/builder_namespace'
9
- require 'rack_dav/http_status'
10
- require 'rack_dav/resource'
11
- require 'rack_dav/file_resource'
12
- require 'rack_dav/handler'
13
- require 'rack_dav/controller'
7
+
8
+ begin
9
+ require 'rack_dav/builder_namespace'
10
+ require 'rack_dav/http_status'
11
+ require 'rack_dav/resource'
12
+ require 'rack_dav/file_resource'
13
+ require 'rack_dav/handler'
14
+ require 'rack_dav/controller'
15
+ rescue LoadError => e
16
+ raise MissingLibrary, "Rack_Dav could not be loaded (is it installed?): #{e.message}"
17
+ end
14
18
 
15
19
 
16
20
  module Capcode
@@ -1,3 +1,3 @@
1
1
  module Capcode
2
- CAPCOD_VERION="0.8.7"
2
+ CAPCOD_VERION="0.8.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Capcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.7
4
+ version: 0.8.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Gr\xC3\xA9goire Lejeune"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-21 00:00:00 +02:00
12
+ date: 2009-11-17 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,10 +45,15 @@ extra_rdoc_files:
45
45
  - lib/capcode.rb
46
46
  - lib/capcode/configuration.rb
47
47
  - lib/capcode/base/db.rb
48
+ - lib/capcode/render/binary.rb
49
+ - lib/capcode/render/email.rb
48
50
  - lib/capcode/render/erb.rb
49
51
  - lib/capcode/render/haml.rb
50
52
  - lib/capcode/render/json.rb
51
53
  - lib/capcode/render/markaby.rb
54
+ - lib/capcode/render/mustache.rb
55
+ - lib/capcode/render/none.rb
56
+ - lib/capcode/render/redirect.rb
52
57
  - lib/capcode/render/sass.rb
53
58
  - lib/capcode/render/static.rb
54
59
  - lib/capcode/render/text.rb
@@ -89,16 +94,23 @@ files:
89
94
  - doc/rdoc/fr_method_index.html
90
95
  - doc/rdoc/index.html
91
96
  - doc/rdoc/rdoc-style.css
97
+ - lib/capcode/base/ar.rb
92
98
  - lib/capcode/base/couchdb.rb
93
99
  - lib/capcode/base/db.rb
94
100
  - lib/capcode/base/dm.rb
101
+ - lib/capcode/base/sq.rb
95
102
  - lib/capcode/configuration.rb
96
103
  - lib/capcode/core_ext.rb
97
104
  - lib/capcode/helpers/auth.rb
105
+ - lib/capcode/render/binary.rb
106
+ - lib/capcode/render/email.rb
98
107
  - lib/capcode/render/erb.rb
99
108
  - lib/capcode/render/haml.rb
100
109
  - lib/capcode/render/json.rb
101
110
  - lib/capcode/render/markaby.rb
111
+ - lib/capcode/render/mustache.rb
112
+ - lib/capcode/render/none.rb
113
+ - lib/capcode/render/redirect.rb
102
114
  - lib/capcode/render/sass.rb
103
115
  - lib/capcode/render/static.rb
104
116
  - lib/capcode/render/text.rb
@@ -109,12 +121,16 @@ files:
109
121
  - examples/auth-basic.rb
110
122
  - examples/auth-digest.rb
111
123
  - examples/auth-webdav.rb
124
+ - examples/blog-ar.rb
125
+ - examples/blog-ar.yml
112
126
  - examples/blog-couchdb-run.rb
113
127
  - examples/blog-couchdb.rb
114
128
  - examples/blog-couchdb.ru
115
129
  - examples/blog-couchdb.yml
116
130
  - examples/blog-dm.rb
117
131
  - examples/blog-dm.yml
132
+ - examples/blog-sq.rb
133
+ - examples/blog-sq.yml
118
134
  - examples/erb/cf.rhtml
119
135
  - examples/erb/cf_layout.rhtml
120
136
  - examples/erb/layout.rhtml
@@ -124,12 +140,21 @@ files:
124
140
  - examples/haml/layout.haml
125
141
  - examples/haml/m_hello.haml
126
142
  - examples/haml/style.sass
127
- - examples/my_blog.db
143
+ - examples/mail/mail_html.rhtml
144
+ - examples/mail/mail_text.rhtml
145
+ - examples/mail/ok.rhtml
146
+ - examples/mail/rubyfr.png
147
+ - examples/mustache/with_class.mustache
148
+ - examples/mustache/without_class.mustache
149
+ - examples/render-binary.rb
150
+ - examples/render-email.rb
128
151
  - examples/render-erb.rb
129
152
  - examples/render-haml_sass.rb
130
153
  - examples/render-image.rb
131
154
  - examples/render-json.rb
132
155
  - examples/render-markaby.rb
156
+ - examples/render-mustache.rb
157
+ - examples/render-redirect.rb
133
158
  - examples/render-static.rb
134
159
  - examples/render-static.ru
135
160
  - examples/render-text.rb
@@ -155,8 +180,10 @@ post_install_message: |+
155
180
  If you want to use Markaby renderer, you must install Markaby.
156
181
  If you want to use HAML renderer, you must install haml.
157
182
  If you want to use SASS renderer, you must install sass.
183
+ If you want to use Mustache renderer, you must install mustache.
158
184
  If you want to use JSON renderer, you must install json.
159
185
  If you want to use WebDAV renderer, you must install rack_dav.
186
+ If you want to use Mail renderer, you must install mail.
160
187
 
161
188
  If For more information about Capcode, see
162
189
  http://capcode.rubyforge.org
Binary file