drupal.rb 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +53 -0
- data/Manifest.txt +23 -0
- data/README.txt +108 -0
- data/Rakefile +21 -0
- data/bin/drupal +4 -0
- data/drupal.rb.gemspec +59 -0
- data/lib/drupal/create_module.rb +276 -0
- data/lib/drupal/install.rb +143 -0
- data/lib/drupal/templates/5.x/base/info +6 -0
- data/lib/drupal/templates/5.x/comments/file +9 -0
- data/lib/drupal/templates/5.x/comments/large +6 -0
- data/lib/drupal/templates/5.x/hooks/block +44 -0
- data/lib/drupal/templates/5.x/hooks/cron +7 -0
- data/lib/drupal/templates/5.x/hooks/form_alter +14 -0
- data/lib/drupal/templates/5.x/hooks/init +7 -0
- data/lib/drupal/templates/5.x/hooks/install +15 -0
- data/lib/drupal/templates/5.x/hooks/menu +24 -0
- data/lib/drupal/templates/5.x/hooks/perm +7 -0
- data/lib/drupal/templates/5.x/txt/changelog +9 -0
- data/lib/drupal/templates/5.x/txt/readme +36 -0
- data/lib/drupal/templates/6.x/base/info +6 -0
- data/lib/drupal/templates/6.x/comments/file +9 -0
- data/lib/drupal/templates/6.x/comments/large +6 -0
- data/lib/drupal/templates/6.x/hooks/block +45 -0
- data/lib/drupal/templates/6.x/hooks/boot +7 -0
- data/lib/drupal/templates/6.x/hooks/cron +7 -0
- data/lib/drupal/templates/6.x/hooks/form_alter +11 -0
- data/lib/drupal/templates/6.x/hooks/init +8 -0
- data/lib/drupal/templates/6.x/hooks/menu +17 -0
- data/lib/drupal/templates/6.x/hooks/perm +7 -0
- data/lib/drupal/templates/6.x/hooks/theme +11 -0
- data/lib/drupal/templates/6.x/txt/changelog +9 -0
- data/lib/drupal/templates/6.x/txt/readme +36 -0
- data/lib/drupal/todo_list.rb +72 -0
- data/lib/drupal.rb +156 -0
- data/test/test_create_module.rb +1 -0
- data/test/test_drupal.rb +6 -0
- data/test/test_install.rb +23 -0
- data/test/test_todo_list.rb +0 -0
- metadata +145 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Implementation of hook_block().
|
4
|
+
*/
|
5
|
+
function [module]_block($op = 'list', $delta = 0, $edit = array()) {
|
6
|
+
switch($op) {
|
7
|
+
case 'list':
|
8
|
+
$blocks = array();
|
9
|
+
$blocks[0] = array(
|
10
|
+
'info' => t('Block desc in listing'),
|
11
|
+
);
|
12
|
+
return $blocks;
|
13
|
+
|
14
|
+
case 'configure':
|
15
|
+
$form = array();
|
16
|
+
switch($delta){
|
17
|
+
default:
|
18
|
+
$form['item'] = array(
|
19
|
+
'#type' => 'textfield',
|
20
|
+
'#title' => t('Form Item'),
|
21
|
+
'#default_value' => variable_get('item_var', 0),
|
22
|
+
);
|
23
|
+
}
|
24
|
+
return $form;
|
25
|
+
|
26
|
+
case 'save':
|
27
|
+
switch($delta){
|
28
|
+
default:
|
29
|
+
variable_set('item_var', $edit['item_var']);
|
30
|
+
}
|
31
|
+
break;
|
32
|
+
|
33
|
+
case 'view':
|
34
|
+
$block = array();
|
35
|
+
switch($delta) {
|
36
|
+
case 0:
|
37
|
+
$block = array(
|
38
|
+
'subject' => t('Block title'),
|
39
|
+
'content' => 'content here',
|
40
|
+
);
|
41
|
+
}
|
42
|
+
return $block;
|
43
|
+
}
|
44
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Implementation of hook_form_alter().
|
4
|
+
*/
|
5
|
+
function [module]_form_alter($form_id, &$form) {
|
6
|
+
//Add a checkbox to the node-type-form.
|
7
|
+
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
|
8
|
+
$form['workflow']['[module]'] = array(
|
9
|
+
'#type' => 'checkbox',
|
10
|
+
'#title' => t('Enable [module]'),
|
11
|
+
'#default_value' => variable_get('[module]_type_'. $form['#node_type']->type, 0),
|
12
|
+
);
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Implementation of hook_install().
|
4
|
+
*/
|
5
|
+
function [module]_install() {
|
6
|
+
switch ($GLOBALS['db_type']) {
|
7
|
+
case 'mysql':
|
8
|
+
case 'mysqli':
|
9
|
+
db_query();
|
10
|
+
break;
|
11
|
+
default:
|
12
|
+
drupal_set_message(t('Database type %dbtype is currently not supported. Please create database table manually.', array('%dbtype' => $GLOBALS['db_type'])), 'error');
|
13
|
+
break;
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Implementation of hook_menu().
|
4
|
+
*/
|
5
|
+
function [module]_menu($may_cache) {
|
6
|
+
$items = array();
|
7
|
+
|
8
|
+
if ($may_cache) {
|
9
|
+
$items[] = array(
|
10
|
+
'path' => 'admin/settings/[module]',
|
11
|
+
'title' => t('[module]'),
|
12
|
+
'callback' => '[module]_settings_page',
|
13
|
+
'access' => user_access('access administration pages'),
|
14
|
+
);
|
15
|
+
$items[] = array(
|
16
|
+
'path' => '',
|
17
|
+
'title' => t(''),
|
18
|
+
'callback' => '',
|
19
|
+
'access' => user_access(''),
|
20
|
+
'type' => MENU_SUGGESTED_ITEM,
|
21
|
+
);
|
22
|
+
}
|
23
|
+
return $items;
|
24
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
$Id$
|
3
|
+
|
4
|
+
|
5
|
+
[module]
|
6
|
+
Provided by [link]
|
7
|
+
Developed by [author]
|
8
|
+
|
9
|
+
-------------------------------------------------------------------------------
|
10
|
+
INSTALLATION
|
11
|
+
-------------------------------------------------------------------------------
|
12
|
+
|
13
|
+
todo
|
14
|
+
|
15
|
+
-------------------------------------------------------------------------------
|
16
|
+
PERMISSIONS
|
17
|
+
-------------------------------------------------------------------------------
|
18
|
+
|
19
|
+
permission
|
20
|
+
- description
|
21
|
+
|
22
|
+
|
23
|
+
-------------------------------------------------------------------------------
|
24
|
+
PUBLIC API
|
25
|
+
-------------------------------------------------------------------------------
|
26
|
+
|
27
|
+
todo
|
28
|
+
|
29
|
+
-------------------------------------------------------------------------------
|
30
|
+
CONVENTIONS
|
31
|
+
-------------------------------------------------------------------------------
|
32
|
+
|
33
|
+
todo
|
34
|
+
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Implementation of hook_block().
|
4
|
+
*/
|
5
|
+
function [module]_block($op = 'list', $delta = 0, $edit = array()) {
|
6
|
+
switch($op) {
|
7
|
+
case 'list':
|
8
|
+
$blocks = array();
|
9
|
+
$blocks[0] = array(
|
10
|
+
'info' => t('Block desc in listing'),
|
11
|
+
'cache' => BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE,
|
12
|
+
);
|
13
|
+
return $blocks;
|
14
|
+
|
15
|
+
case 'configure':
|
16
|
+
$form = array();
|
17
|
+
switch($delta){
|
18
|
+
default:
|
19
|
+
$form['item'] = array(
|
20
|
+
'#type' => 'textfield',
|
21
|
+
'#title' => t('Form Item'),
|
22
|
+
'#default_value' => variable_get('item_var', 0),
|
23
|
+
);
|
24
|
+
}
|
25
|
+
return $form;
|
26
|
+
|
27
|
+
case 'save':
|
28
|
+
switch($delta){
|
29
|
+
default:
|
30
|
+
variable_set('item_var', $edit['item_var']);
|
31
|
+
}
|
32
|
+
break;
|
33
|
+
|
34
|
+
case 'view':
|
35
|
+
$block = array();
|
36
|
+
switch($delta) {
|
37
|
+
case 0:
|
38
|
+
$block = array(
|
39
|
+
'subject' => t('Block title'),
|
40
|
+
'content' => 'content here',
|
41
|
+
);
|
42
|
+
}
|
43
|
+
return $block;
|
44
|
+
}
|
45
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Implementation of hook_menu().
|
4
|
+
*/
|
5
|
+
function [module]_menu() {
|
6
|
+
$items = array();
|
7
|
+
|
8
|
+
$items['admin/settings/[module]'] = array(
|
9
|
+
'title' => '[module]',
|
10
|
+
'page callback' => 'drupal_get_form',
|
11
|
+
'page arguments' => array('[module]_settings'),
|
12
|
+
'access arguments' => array('administer [module]'),
|
13
|
+
'file' => '[module].admin.inc',
|
14
|
+
);
|
15
|
+
|
16
|
+
return $items;
|
17
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
$Id$
|
3
|
+
|
4
|
+
|
5
|
+
[module]
|
6
|
+
Provided by [link]
|
7
|
+
Developed by [author]
|
8
|
+
|
9
|
+
-------------------------------------------------------------------------------
|
10
|
+
INSTALLATION
|
11
|
+
-------------------------------------------------------------------------------
|
12
|
+
|
13
|
+
todo
|
14
|
+
|
15
|
+
-------------------------------------------------------------------------------
|
16
|
+
PERMISSIONS
|
17
|
+
-------------------------------------------------------------------------------
|
18
|
+
|
19
|
+
permission
|
20
|
+
- description
|
21
|
+
|
22
|
+
|
23
|
+
-------------------------------------------------------------------------------
|
24
|
+
PUBLIC API
|
25
|
+
-------------------------------------------------------------------------------
|
26
|
+
|
27
|
+
todo
|
28
|
+
|
29
|
+
-------------------------------------------------------------------------------
|
30
|
+
CONVENTIONS
|
31
|
+
-------------------------------------------------------------------------------
|
32
|
+
|
33
|
+
todo
|
34
|
+
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
|
2
|
+
class Drupal
|
3
|
+
class Todo_List
|
4
|
+
|
5
|
+
# Run todo list
|
6
|
+
def run(arguments)
|
7
|
+
@total = 0
|
8
|
+
@arguments = arguments
|
9
|
+
@total_only = true if @arguments[0] == 'total'
|
10
|
+
@arguments.shift if @total_only == true
|
11
|
+
parse_dir('.') if @arguments.empty?
|
12
|
+
for argument in @arguments
|
13
|
+
parse_file(argument) if File.file?(argument)
|
14
|
+
parse_dir(argument) if File.directory?(argument)
|
15
|
+
end
|
16
|
+
puts "Total todo items: #{@total}" if @total_only == true
|
17
|
+
end
|
18
|
+
|
19
|
+
# Parse file for todo items.
|
20
|
+
def parse_file(filepath)
|
21
|
+
File.open(filepath) do |file|
|
22
|
+
items = []
|
23
|
+
linenumber = 0
|
24
|
+
file.each_line do |line|
|
25
|
+
linenumber += 1
|
26
|
+
if summary = ToDo.extract_summary(line)
|
27
|
+
context = ToDo.extract_context(linenumber, file)
|
28
|
+
item = ToDo.new(linenumber, summary, context)
|
29
|
+
@total += 1
|
30
|
+
items << item.to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
puts "\n" + filepath unless items.empty? || @total_only == true
|
34
|
+
items.each{ |item| puts item } unless @total_only == true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Parse directory for todo items.
|
39
|
+
def parse_dir(dir)
|
40
|
+
Dir["#{dir == '.' ? '.' : dir}/**/*"].each do |file|
|
41
|
+
parse_file(file) if File.file?(file)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# TODO: example.
|
48
|
+
class ToDo
|
49
|
+
attr_accessor :linenumber, :summary, :context
|
50
|
+
|
51
|
+
def initialize (linenumber, summary, context)
|
52
|
+
@linenumber = linenumber
|
53
|
+
@summary = summary
|
54
|
+
@context = context
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_s
|
58
|
+
"#{@linenumber}: #{@summary}\n#{@context}\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
def ToDo.extract_summary(line)
|
62
|
+
matches = line.match /(?:#|\/\/|\/\*|@)[\s]*todo:?[\s]*(.+)$/i
|
63
|
+
matches[1] unless matches.nil? || matches.length <= 0
|
64
|
+
end
|
65
|
+
|
66
|
+
def ToDo.extract_context(linenumber, file)
|
67
|
+
file.rewind
|
68
|
+
list = file.to_a
|
69
|
+
#rewind one line (one line above) then add the line itself and three lines below.
|
70
|
+
list.slice!(linenumber - 1, 5)
|
71
|
+
end
|
72
|
+
end
|
data/lib/drupal.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# == SYNOPSIS:
|
4
|
+
#
|
5
|
+
# drupal [options] [arguments]
|
6
|
+
#
|
7
|
+
# == ARGUMENTS:
|
8
|
+
#
|
9
|
+
# create module <module_name> [dir] Generates a module skeleton from an interactive wizard. Current directory unless [dir] is specified.
|
10
|
+
# todo list [total] Displays list of todo items or a total.
|
11
|
+
# install <core | project> [dir] [5.x|6.x|7.x]
|
12
|
+
# Install a Drupal project or core itself to [dir] (defaults to curent dir) for version (defaults to 6.x)
|
13
|
+
#
|
14
|
+
# == OPTIONS:
|
15
|
+
#
|
16
|
+
# -h, --help Display this help information.
|
17
|
+
# -V, --version Display version of the Drupal development tool.
|
18
|
+
#
|
19
|
+
# == EXAMPLES:
|
20
|
+
#
|
21
|
+
# Create a new module in the current directory.
|
22
|
+
# drupal create module my_module
|
23
|
+
#
|
24
|
+
# Create a new module in a specific directory.
|
25
|
+
# drupal create module my_module ./sites/all/modules
|
26
|
+
#
|
27
|
+
# View todo list for current directory.
|
28
|
+
# drupal todo list
|
29
|
+
#
|
30
|
+
# View todo list for multiple files or directories.
|
31
|
+
# drupal todo list ./sites/all/modules/mymodule
|
32
|
+
#
|
33
|
+
# View total todo items only.
|
34
|
+
# drupal todo list total ./sites/all/modules
|
35
|
+
#
|
36
|
+
# Install a module to the modules folder in my new installation (from drupal root)
|
37
|
+
# drupal install devel ./sites/all/modules
|
38
|
+
#
|
39
|
+
# Install a module when in the 'modules directory
|
40
|
+
# drupal install devel
|
41
|
+
#
|
42
|
+
# Install a 5.x module when in the 'modules directory
|
43
|
+
# drupal install devel . 5.x
|
44
|
+
#
|
45
|
+
# Install several modules to the modules folder
|
46
|
+
# drupal install devel,pathauto,err,ac ./sites/all/modules
|
47
|
+
#
|
48
|
+
|
49
|
+
require 'optparse'
|
50
|
+
require 'ostruct'
|
51
|
+
require File.dirname(__FILE__) + '/drupal/create_module'
|
52
|
+
require File.dirname(__FILE__) + '/drupal/todo_list'
|
53
|
+
require File.dirname(__FILE__) + '/drupal/install'
|
54
|
+
|
55
|
+
class Drupal
|
56
|
+
|
57
|
+
MAJOR = 0
|
58
|
+
MINOR = 0
|
59
|
+
TINY = 9
|
60
|
+
VERSION = [MAJOR, MINOR, TINY].join('.')
|
61
|
+
|
62
|
+
# Run the drupal development tool.
|
63
|
+
def run(arguments)
|
64
|
+
@arguments = arguments || []
|
65
|
+
@options = OpenStruct.new
|
66
|
+
abort 'Arguments required. Use --help for additional information.' if @arguments.empty?
|
67
|
+
parse_options
|
68
|
+
determine_handler
|
69
|
+
execute_handler
|
70
|
+
end
|
71
|
+
|
72
|
+
# Parse stdin for options.
|
73
|
+
def parse_options
|
74
|
+
opts = OptionParser.new
|
75
|
+
opts.on('-h', '--help') { output_help }
|
76
|
+
opts.on('-V', '--version') { output_version }
|
77
|
+
opts.parse!(@arguments)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Determine handler based on the current arguments.
|
81
|
+
def determine_handler
|
82
|
+
@handler = @arguments.shift.capitalize
|
83
|
+
while !@arguments.empty? && !is_handler(@handler) do
|
84
|
+
@handler << '_' + @arguments.shift.capitalize
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Execute the handler if it was found.
|
89
|
+
def execute_handler
|
90
|
+
abort 'Invalid command.' if !is_handler(@handler)
|
91
|
+
eval("Drupal::#{@handler}.new.run(@arguments)")
|
92
|
+
end
|
93
|
+
|
94
|
+
# Check existance of a handler.
|
95
|
+
def is_handler(klass)
|
96
|
+
Drupal.const_defined?(klass)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Output help information.
|
100
|
+
def output_help
|
101
|
+
# TODO: utilize RDoc
|
102
|
+
puts <<-USAGE
|
103
|
+
|
104
|
+
SYNOPSIS:
|
105
|
+
|
106
|
+
drupal [options] [arguments]
|
107
|
+
|
108
|
+
ARGUMENTS:
|
109
|
+
|
110
|
+
create module <module_name> [dir] Generates a module skeleton from an interactive wizard. Current directory unless [dir] is specified.
|
111
|
+
todo list [total] Displays list of todo items or a total.
|
112
|
+
install <core | project> [dir] [5.x|6.x|7.x]
|
113
|
+
Install a Drupal project or core itself to [dir] (defaults to curent dir) for version (defaults to 6.x)
|
114
|
+
|
115
|
+
EXAMPLES:
|
116
|
+
|
117
|
+
Create a new module in the current directory.
|
118
|
+
drupal create module my_module
|
119
|
+
|
120
|
+
Create a new module in a specific directory.
|
121
|
+
drupal create module my_module ./sites/all/modules
|
122
|
+
|
123
|
+
View todo list for current directory.
|
124
|
+
drupal todo list
|
125
|
+
|
126
|
+
View todo list for multiple files or directories.
|
127
|
+
drupal todo list ./sites/all/modules/mymodule
|
128
|
+
|
129
|
+
View total todo items only.
|
130
|
+
drupal todo list total ./sites/all/modules
|
131
|
+
|
132
|
+
Install drupal core to the current directory.
|
133
|
+
drupal install core
|
134
|
+
|
135
|
+
Install a 5.x module when in the 'modules directory
|
136
|
+
drupal install devel . 5.x
|
137
|
+
|
138
|
+
Install a module to the modules folder in my new installation (from drupal root)
|
139
|
+
drupal install devel ./sites/all/modules
|
140
|
+
|
141
|
+
Install a module when in the 'modules directory
|
142
|
+
drupal install devel
|
143
|
+
|
144
|
+
USAGE
|
145
|
+
exit
|
146
|
+
end
|
147
|
+
|
148
|
+
# Output version information.
|
149
|
+
def output_version
|
150
|
+
puts "Version #{Drupal::VERSION}"
|
151
|
+
exit
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/test/test_drupal.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
class DrupalInstall < Test::Unit::TestCase
|
3
|
+
def setup
|
4
|
+
Drupal.new.run('install ab'.split)
|
5
|
+
Kernel.system "mkdir _modules"
|
6
|
+
Drupal.new.run('install devel ./_modules'.split)
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
Kernel.system "rm -fr ./ab/*"
|
11
|
+
Kernel.system "rmdir ./ab"
|
12
|
+
Kernel.system "rm -fr ./_modules/*"
|
13
|
+
Kernel.system "rmdir ./_modules"
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_contrib_cwd
|
17
|
+
assert(File.directory?('./ab'), 'Failed to install ab module in cwd.')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_contrib_dir
|
21
|
+
assert(File.directory?('./_modules/devel'), 'Failed to install devel to _modules directory.')
|
22
|
+
end
|
23
|
+
end
|
File without changes
|