dm-drupal 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +19 -0
- metadata +2 -7
- data/lib/drupal/cck/builder.rb +0 -77
- data/lib/drupal/cck/fields.rb +0 -51
- data/lib/drupal/cck.rb +0 -78
- data/lib/drupal/node.rb +0 -49
- data/lib/drupal/user.rb +0 -18
- data/lib/drupal.rb +0 -19
data/README
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
== DM Drupal ==
|
2
|
+
|
3
|
+
Its a Datamapper wrapper for a drupal+cck database.
|
4
|
+
|
5
|
+
lots of eval right now. sorry.
|
6
|
+
|
7
|
+
== Using Hooks ==
|
8
|
+
|
9
|
+
this is for associating with dynamic cck fields that don't exist when the app loads.
|
10
|
+
|
11
|
+
class BlogPost
|
12
|
+
include DataMapper::Resource
|
13
|
+
post_drupal do
|
14
|
+
has 1, :drupal_blog_post,
|
15
|
+
:repository => repository(:drupal),
|
16
|
+
:class_name => 'Drupal::BlogPost',
|
17
|
+
:child_key => ['legacy_blog_post_id']
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-drupal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- quinn shanahan
|
@@ -22,12 +22,7 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
-
-
|
26
|
-
- lib/drupal/cck/fields.rb
|
27
|
-
- lib/drupal/cck.rb
|
28
|
-
- lib/drupal/node.rb
|
29
|
-
- lib/drupal/user.rb
|
30
|
-
- lib/drupal.rb
|
25
|
+
- README
|
31
26
|
has_rdoc: true
|
32
27
|
homepage:
|
33
28
|
licenses: []
|
data/lib/drupal/cck/builder.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
module Drupal
|
2
|
-
module CCK
|
3
|
-
class Builder
|
4
|
-
def self.code
|
5
|
-
types.
|
6
|
-
map{|t| table = Table.new t}.
|
7
|
-
select{|t| t.valid?}.
|
8
|
-
join("\n")
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.types
|
12
|
-
@types ||= Drupal::Repository.adapter.query('select type from node').uniq
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.fields
|
16
|
-
@fields ||= Drupal::Repository.adapter.query('show tables').select{|t| t.match(/^content_field/)}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Table
|
21
|
-
attr_accessor :type
|
22
|
-
|
23
|
-
def initialize type
|
24
|
-
self.type = type
|
25
|
-
end
|
26
|
-
|
27
|
-
def table
|
28
|
-
"content_type_#{type}"
|
29
|
-
end
|
30
|
-
|
31
|
-
def fields
|
32
|
-
Drupal::CCK::ContentNodeFieldInstance.all :type_name => type
|
33
|
-
end
|
34
|
-
|
35
|
-
def columns
|
36
|
-
@columns ||= fields
|
37
|
-
end
|
38
|
-
|
39
|
-
def ignore_columns
|
40
|
-
%w{nid vid}
|
41
|
-
end
|
42
|
-
|
43
|
-
def to_s
|
44
|
-
"
|
45
|
-
class #{type.camel_case}
|
46
|
-
#{Drupal.common}
|
47
|
-
storage_names[:drupal] = '#{table}'
|
48
|
-
property :nid, Serial
|
49
|
-
property :vid, Integer
|
50
|
-
belongs_to :node,
|
51
|
-
:child_key => [:nid]
|
52
|
-
#{columns.map{|c| c.to_s}.join "\n"}
|
53
|
-
def self.type; :#{type}; end
|
54
|
-
extend CCK::FieldMethods
|
55
|
-
end
|
56
|
-
"
|
57
|
-
end
|
58
|
-
|
59
|
-
def valid?
|
60
|
-
columns
|
61
|
-
true
|
62
|
-
rescue MysqlError
|
63
|
-
false
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.generate
|
69
|
-
Drupal.class_eval do
|
70
|
-
eval( CCK::Builder.fields.map do |field|
|
71
|
-
CCK::ThroughField.new field
|
72
|
-
end.join("\n") )
|
73
|
-
|
74
|
-
eval CCK::Builder.code
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
data/lib/drupal/cck/fields.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
module Drupal
|
2
|
-
module CCK
|
3
|
-
module FieldMethods
|
4
|
-
def fields
|
5
|
-
Drupal::CCK::ContentNodeFieldInstance.all :type_name => type
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
class ThroughField
|
10
|
-
attr_accessor :field_name, :table
|
11
|
-
|
12
|
-
def initialize field
|
13
|
-
self.table = field
|
14
|
-
self.field_name = field.match(/^content_field_(.*)/)[1]
|
15
|
-
end
|
16
|
-
|
17
|
-
def field
|
18
|
-
@field ||= ContentNodeField.first :field_name => "field_#{field_name}"
|
19
|
-
end
|
20
|
-
|
21
|
-
def valid?
|
22
|
-
!field.nil?
|
23
|
-
end
|
24
|
-
|
25
|
-
def field_type
|
26
|
-
case field.type
|
27
|
-
when 'userreference'
|
28
|
-
"belongs_to :user,
|
29
|
-
:class_name => 'Drupal::User',
|
30
|
-
:child_key => [:#{field.field_name}_uid]"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_s
|
35
|
-
return "" unless valid?
|
36
|
-
"
|
37
|
-
class #{field_name.camel_case}
|
38
|
-
#{Drupal.common}
|
39
|
-
storage_names[:drupal] = '#{table}'
|
40
|
-
|
41
|
-
belongs_to :node,
|
42
|
-
:class_name => 'Drupal::Node',
|
43
|
-
:child_key => [:nid]
|
44
|
-
Drupal::User
|
45
|
-
#{field_type}
|
46
|
-
end
|
47
|
-
"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/lib/drupal/cck.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
module Drupal
|
2
|
-
module CCK
|
3
|
-
module NodeMethods
|
4
|
-
def cck_class
|
5
|
-
@cck_class ||= eval("Drupal::#{type.camel_case}")
|
6
|
-
end
|
7
|
-
|
8
|
-
def cck
|
9
|
-
@cck ||= cck_class.first(:nid => nid)
|
10
|
-
end
|
11
|
-
|
12
|
-
def find_or_create_cck
|
13
|
-
return cck if cck
|
14
|
-
@cck = cck_class.create! :vid => vid, :nid => nid
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class ContentNodeFieldInstance
|
19
|
-
eval Drupal.common
|
20
|
-
storage_names[:drupal] = 'content_node_field_instance'
|
21
|
-
|
22
|
-
property :field_name, String,
|
23
|
-
:length => 32, :key => true
|
24
|
-
property :type_name, String,
|
25
|
-
:length => 32, :key => true
|
26
|
-
|
27
|
-
def field
|
28
|
-
@field ||= ContentNodeField.first :field_name => field_name
|
29
|
-
end
|
30
|
-
|
31
|
-
def field_type
|
32
|
-
@field_type ||= field.type
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_s
|
36
|
-
f = field_name.match(/^field_(.*)/)[1]
|
37
|
-
case field_type
|
38
|
-
when 'userreference'
|
39
|
-
if through?
|
40
|
-
r = "has 1, :#{f},
|
41
|
-
:class_name => Drupal::#{f.camel_case},
|
42
|
-
:child_key => [:#{field_name}_uid]"
|
43
|
-
else
|
44
|
-
r = "belongs_to :#{field_name},
|
45
|
-
:class_name => 'Drupal::User'"
|
46
|
-
end
|
47
|
-
# when 'nodereference'
|
48
|
-
# r = "belongs_to :#{field_name},
|
49
|
-
# :class_name => 'Drupal::Node',
|
50
|
-
# :child_key => [:#{field_name}_nid]"
|
51
|
-
# else
|
52
|
-
# r = "property :#{field_name}, #{type}"
|
53
|
-
# r += ", :field => '#{field_name}_value'"
|
54
|
-
end
|
55
|
-
r
|
56
|
-
end
|
57
|
-
|
58
|
-
def through?
|
59
|
-
false
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class ContentNodeField
|
64
|
-
eval Drupal.common
|
65
|
-
storage_names[:drupal] = 'content_node_field'
|
66
|
-
|
67
|
-
property :type, String,
|
68
|
-
:length => 127
|
69
|
-
property :field_name, String,
|
70
|
-
:length => 32
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
Node.send :include, CCK::NodeMethods
|
75
|
-
end
|
76
|
-
|
77
|
-
require 'drupal/cck/fields.rb'
|
78
|
-
require 'drupal/cck/builder.rb'
|
data/lib/drupal/node.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
module Drupal
|
2
|
-
class Node
|
3
|
-
eval Drupal.common
|
4
|
-
storage_names[:drupal] = 'node'
|
5
|
-
|
6
|
-
property :nid, Serial
|
7
|
-
property :vid, Integer
|
8
|
-
property :uid, Integer
|
9
|
-
property :type, String
|
10
|
-
property :title, String
|
11
|
-
|
12
|
-
after :save, :write_node_revision
|
13
|
-
|
14
|
-
def write_node_revision
|
15
|
-
find_or_init_node_revision.attributes = {
|
16
|
-
:nid => nid,
|
17
|
-
:vid => vid,
|
18
|
-
:uid => uid,
|
19
|
-
:title => title,
|
20
|
-
:body => '',
|
21
|
-
:teaser => '',
|
22
|
-
:log => ''
|
23
|
-
}
|
24
|
-
node_revision.save!
|
25
|
-
end
|
26
|
-
|
27
|
-
def find_or_init_node_revision
|
28
|
-
return node_revision if node_revision
|
29
|
-
@node_revision = Drupal::NodeRevision.new
|
30
|
-
end
|
31
|
-
|
32
|
-
def node_revision
|
33
|
-
@node_revision ||= Drupal::NodeRevision.get nid
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class NodeRevision
|
38
|
-
eval Drupal.common
|
39
|
-
storage_names[:drupal] = 'node_revisions'
|
40
|
-
|
41
|
-
property :nid, Serial
|
42
|
-
property :vid, Integer
|
43
|
-
property :uid, Integer
|
44
|
-
property :title, String
|
45
|
-
property :body, Text
|
46
|
-
property :teaser, Text
|
47
|
-
property :log, Text
|
48
|
-
end
|
49
|
-
end
|
data/lib/drupal/user.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Drupal
|
2
|
-
class User
|
3
|
-
eval Drupal.common
|
4
|
-
storage_names[:drupal] = 'users'
|
5
|
-
|
6
|
-
property :uid, Serial
|
7
|
-
property :name, String,
|
8
|
-
:length => 60,
|
9
|
-
:nullable => false
|
10
|
-
has n, :nodes,
|
11
|
-
:child_key => [:uid],
|
12
|
-
:repository => Drupal::Repository
|
13
|
-
|
14
|
-
def profile
|
15
|
-
Drupal::Node.first :type => 'profile', :uid => uid
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/drupal.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Drupal
|
2
|
-
RepositoryName = :drupal
|
3
|
-
Repository = repository(Drupal::RepositoryName)
|
4
|
-
|
5
|
-
def self.common
|
6
|
-
"
|
7
|
-
include DataMapper::Resource
|
8
|
-
|
9
|
-
def self.default_repository_name
|
10
|
-
Drupal::RepositoryName
|
11
|
-
end
|
12
|
-
"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
$:<< File.expand_path(Pathname.new(__FILE__).dirname)
|
17
|
-
require 'drupal/user'
|
18
|
-
require 'drupal/node'
|
19
|
-
require 'drupal/cck'
|