capcode-base-datamapper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 glejeune
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = capcode-base-datamapper
2
+
3
+ Capcode plugin to access databases via DataMapper
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "capcode-base-datamapper"
8
+ gem.summary = %Q{Capcode plugin to access databases via DataMapper}
9
+ gem.description = gem.summary
10
+ gem.email = "gregoire.lejeune@free.fr"
11
+ gem.homepage = "http://github.com/glejeune/Capcode.more/tree/master/%s" % gem.name
12
+ gem.authors = ["Gregoire Lejeune"]
13
+
14
+ gem.add_dependency('dm-core')
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,47 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{capcode-base-datamapper}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Gregoire Lejeune"]
12
+ s.date = %q{2010-01-07}
13
+ s.description = %q{Capcode plugin to access databases via DataMapper}
14
+ s.email = %q{gregoire.lejeune@free.fr}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "capcode-base-datamapper.gemspec",
24
+ "examples/blog-dm.rb",
25
+ "examples/blog-dm.yml",
26
+ "lib/capcode/base/dm.rb"
27
+ ]
28
+ s.homepage = %q{http://github.com/glejeune/Capcode.more/tree/master/capcode-base-datamapper}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.5}
32
+ s.summary = %q{Capcode plugin to access databases via DataMapper}
33
+
34
+ if s.respond_to? :specification_version then
35
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
36
+ s.specification_version = 3
37
+
38
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
39
+ s.add_runtime_dependency(%q<dm-core>, [">= 0"])
40
+ else
41
+ s.add_dependency(%q<dm-core>, [">= 0"])
42
+ end
43
+ else
44
+ s.add_dependency(%q<dm-core>, [">= 0"])
45
+ end
46
+ end
47
+
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'capcode'
3
+ $:.unshift( "../lib" )
4
+ require 'capcode/base/dm'
5
+
6
+ class Story < Capcode::Base
7
+ include Capcode::Resource
8
+
9
+ property :id, Serial
10
+ property :title, String
11
+ property :body, String
12
+ property :date, String
13
+ end
14
+
15
+ module Capcode
16
+ class HTTPError
17
+ def r404(f)
18
+ "Pas glop !!! #{f} est inconnu !!!"
19
+ end
20
+ end
21
+
22
+ class Index < Route '/'
23
+ def get
24
+ r = "<html><body>"
25
+
26
+ story = Story.all
27
+
28
+ story.each do |s|
29
+ r += "<h2>#{s.title}</h2><small>#{s.date} - <a href='#{URL( Remove, s.id )}'>Delete this entry</a></small><p>#{s.body}</p>"
30
+ end
31
+
32
+ r+"<hr /><a href='#{URL(Add)}'>Add a new entry</a></body></html>"
33
+ end
34
+ end
35
+
36
+ class Remove < Route '/remove/([^\/]*)'
37
+ def get( id )
38
+ Story.get!(id).destroy
39
+ redirect( Index )
40
+ end
41
+ end
42
+
43
+ class Add < Route '/add'
44
+ def get
45
+ '
46
+ <html><body>
47
+ <h1>Add a new entry</h1>
48
+ <form method="POST">
49
+ Titre : <input type="text" name="title"><br />
50
+ <textarea name="body"></textarea><br />
51
+ <input type="submit">
52
+ </form>
53
+ </body></html>
54
+ '
55
+ end
56
+ def post
57
+ Story.new( :title => params['title'], :body => params['body'], :date => Time.now.to_s ).save
58
+ redirect( Index )
59
+ end
60
+ end
61
+ end
62
+
63
+ Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-dm.yml" )
@@ -0,0 +1,2 @@
1
+ adapter: sqlite3
2
+ database: my_blog.db
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ begin
3
+ require 'dm-core'
4
+ rescue LoadError => e
5
+ raise Capcode::MissingLibrary, "DataMapper could not be loaded (is it installed?): #{e.message}"
6
+ end
7
+ require 'yaml'
8
+ require 'logger'
9
+
10
+ module Capcode
11
+ Resource = DataMapper::Resource
12
+
13
+ # use DataMapper
14
+ #
15
+ # class Story < Capcode::Base
16
+ # include Capcode::Base
17
+ # property :id, Integer, :serial => true
18
+ # property :title, String
19
+ # property :body, String
20
+ # property :date, String
21
+ # end
22
+ class Base
23
+ end
24
+
25
+ class << self
26
+ def db_connect( dbfile, logfile ) #:nodoc:
27
+ dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
28
+ DataMapper.setup(:default, dbconfig)
29
+ DataMapper::Logger.new(logfile, :debug)
30
+ DataMapper.auto_upgrade!
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capcode-base-datamapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gregoire Lejeune
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-07 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: dm-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Capcode plugin to access databases via DataMapper
26
+ email: gregoire.lejeune@free.fr
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - VERSION
38
+ - capcode-base-datamapper.gemspec
39
+ - examples/blog-dm.rb
40
+ - examples/blog-dm.yml
41
+ - lib/capcode/base/dm.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/glejeune/Capcode.more/tree/master/capcode-base-datamapper
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Capcode plugin to access databases via DataMapper
70
+ test_files: []
71
+