visionmedia-drupal 0.0.2
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 +11 -0
- data/Manifest.txt +22 -0
- data/README.txt +83 -0
- data/Rakefile +16 -0
- data/bin/drupal +4 -0
- data/drupal.gemspec +39 -0
- data/lib/drupal.rb +127 -0
- data/lib/drupal/create_module.rb +202 -0
- data/lib/drupal/install.rb +55 -0
- data/lib/drupal/templates/comments/file +9 -0
- data/lib/drupal/templates/comments/large +6 -0
- data/lib/drupal/templates/hooks/block +45 -0
- data/lib/drupal/templates/hooks/boot +7 -0
- data/lib/drupal/templates/hooks/cron +7 -0
- data/lib/drupal/templates/hooks/form_alter +11 -0
- data/lib/drupal/templates/hooks/init +7 -0
- data/lib/drupal/templates/hooks/menu +17 -0
- data/lib/drupal/templates/hooks/perm +7 -0
- data/lib/drupal/templates/hooks/schema +37 -0
- data/lib/drupal/templates/hooks/theme +11 -0
- data/lib/drupal/templates/txt/changelog +8 -0
- data/lib/drupal/templates/txt/readme +36 -0
- data/lib/drupal/todo_list.rb +40 -0
- data/test/test_drupal.rb +0 -0
- metadata +78 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
History.txt
|
|
2
|
+
Manifest.txt
|
|
3
|
+
README.txt
|
|
4
|
+
Rakefile
|
|
5
|
+
bin/drupal
|
|
6
|
+
lib/drupal.rb
|
|
7
|
+
lib/drupal/todo_list.rb
|
|
8
|
+
lib/drupal/create_module.rb
|
|
9
|
+
lib/drupal/install.rb
|
|
10
|
+
lib/drupal/templates/comments/file
|
|
11
|
+
lib/drupal/templates/comments/large
|
|
12
|
+
lib/drupal/templates/hooks/block
|
|
13
|
+
lib/drupal/templates/hooks/boot
|
|
14
|
+
lib/drupal/templates/hooks/cron
|
|
15
|
+
lib/drupal/templates/hooks/form_alter
|
|
16
|
+
lib/drupal/templates/hooks/init
|
|
17
|
+
lib/drupal/templates/hooks/menu
|
|
18
|
+
lib/drupal/templates/hooks/perm
|
|
19
|
+
lib/drupal/templates/hooks/schema
|
|
20
|
+
lib/drupal/templates/hooks/theme
|
|
21
|
+
lib/drupal/templates/txt/changelog
|
|
22
|
+
lib/drupal/templates/txt/readme
|
data/README.txt
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
= drupal
|
|
2
|
+
|
|
3
|
+
http://vision-media.ca/resources/ruby/drupal-module-builder-gem
|
|
4
|
+
|
|
5
|
+
== DESCRIPTION:
|
|
6
|
+
|
|
7
|
+
Drupal is an open source Ruby development tool allowing developers
|
|
8
|
+
to quickly generate and manage Drupal modules.
|
|
9
|
+
|
|
10
|
+
== SYNOPSIS:
|
|
11
|
+
|
|
12
|
+
drupal [options] [arguments]
|
|
13
|
+
|
|
14
|
+
== REQUIREMENTS:
|
|
15
|
+
|
|
16
|
+
none
|
|
17
|
+
|
|
18
|
+
== ARGUMENTS:
|
|
19
|
+
|
|
20
|
+
create module <module_name> Generates a module skeleton from an interactive wizard.
|
|
21
|
+
todo list [total] Displays list of todo items or a total.
|
|
22
|
+
|
|
23
|
+
== OPTIONS:
|
|
24
|
+
|
|
25
|
+
-h, --help Display this help information.
|
|
26
|
+
-V, --version Display version of the Drupal development tool.
|
|
27
|
+
|
|
28
|
+
== EXAMPLES:
|
|
29
|
+
|
|
30
|
+
Create a new module in the current directory.
|
|
31
|
+
drupal create module my_module
|
|
32
|
+
|
|
33
|
+
Create a new module in a specific directory.
|
|
34
|
+
drupal create module my_module ./sites/all/modules
|
|
35
|
+
|
|
36
|
+
View todo list for current directory.
|
|
37
|
+
drupal todo list
|
|
38
|
+
|
|
39
|
+
View todo list for multiple files or directories.
|
|
40
|
+
drupal todo list ./sites/all/modules/mymodule
|
|
41
|
+
|
|
42
|
+
View total todo items only.
|
|
43
|
+
drupal todo list total ./sites/all/modules
|
|
44
|
+
|
|
45
|
+
== TODO:
|
|
46
|
+
|
|
47
|
+
* Add formatted help option
|
|
48
|
+
* Add download of Drupal core install via 'install core [version]'
|
|
49
|
+
* Support versions for installer
|
|
50
|
+
* Support version prompt for project installation
|
|
51
|
+
* Add graceful error handling
|
|
52
|
+
* Add tests
|
|
53
|
+
|
|
54
|
+
== AUTHOR:
|
|
55
|
+
|
|
56
|
+
TJ Holowaychuk
|
|
57
|
+
tj@vision-media.ca
|
|
58
|
+
http://vision-media.ca
|
|
59
|
+
|
|
60
|
+
== LICENSE:
|
|
61
|
+
|
|
62
|
+
(The MIT License)
|
|
63
|
+
|
|
64
|
+
Copyright (c) 2008 FIX
|
|
65
|
+
|
|
66
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
67
|
+
a copy of this software and associated documentation files (the
|
|
68
|
+
'Software'), to deal in the Software without restriction, including
|
|
69
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
70
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
71
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
72
|
+
the following conditions:
|
|
73
|
+
|
|
74
|
+
The above copyright notice and this permission notice shall be
|
|
75
|
+
included in all copies or substantial portions of the Software.
|
|
76
|
+
|
|
77
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
78
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
79
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
80
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
81
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
82
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
83
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require File.dirname(__FILE__) + '/lib/drupal'
|
|
5
|
+
|
|
6
|
+
desc 'Build and install ruby gem.'
|
|
7
|
+
task :build do
|
|
8
|
+
sh "sudo gem build ./drupal.gemspec"
|
|
9
|
+
sh "sudo gem install drupal-#{Drupal::VERSION}.gem"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
desc 'Remove ruby gem build data.'
|
|
13
|
+
task :remove do
|
|
14
|
+
sh "sudo gem uninstall drupal"
|
|
15
|
+
sh "sudo rm drupal-#{Drupal::VERSION}.gem"
|
|
16
|
+
end
|
data/bin/drupal
ADDED
data/drupal.gemspec
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = "drupal"
|
|
3
|
+
s.version = "0.0.2"
|
|
4
|
+
s.date = "2008-09-29"
|
|
5
|
+
s.summary = "Drupal development kit"
|
|
6
|
+
s.email = "tj@vision-media.ca"
|
|
7
|
+
s.homepage = "http://vision-media.ca/resources/drupal/drupal-module-builder-gem"
|
|
8
|
+
s.description = "Drupal is an open source Ruby development tool allowing developers to quickly generate and manage Drupal modules."
|
|
9
|
+
s.has_rdoc = true
|
|
10
|
+
s.require_path = "lib"
|
|
11
|
+
s.authors = ["tj@vision-media.ca"]
|
|
12
|
+
s.files = ["History.txt",
|
|
13
|
+
"Manifest.txt",
|
|
14
|
+
"README.txt",
|
|
15
|
+
"Rakefile",
|
|
16
|
+
"drupal.gemspec",
|
|
17
|
+
"lib/drupal.rb",
|
|
18
|
+
"lib/drupal/create_module.rb",
|
|
19
|
+
"lib/drupal/todo_list.rb",
|
|
20
|
+
"lib/drupal/install.rb",
|
|
21
|
+
"lib/drupal/templates/comments/file",
|
|
22
|
+
"lib/drupal/templates/comments/large",
|
|
23
|
+
"lib/drupal/templates/hooks/block",
|
|
24
|
+
"lib/drupal/templates/hooks/boot",
|
|
25
|
+
"lib/drupal/templates/hooks/cron",
|
|
26
|
+
"lib/drupal/templates/hooks/form_alter",
|
|
27
|
+
"lib/drupal/templates/hooks/init",
|
|
28
|
+
"lib/drupal/templates/hooks/menu",
|
|
29
|
+
"lib/drupal/templates/hooks/perm",
|
|
30
|
+
"lib/drupal/templates/hooks/schema",
|
|
31
|
+
"lib/drupal/templates/hooks/theme",
|
|
32
|
+
"lib/drupal/templates/txt/changelog",
|
|
33
|
+
"lib/drupal/templates/txt/readme",
|
|
34
|
+
"bin/drupal"]
|
|
35
|
+
s.executables = ["drupal"]
|
|
36
|
+
s.test_files = ["test/test_drupal.rb"]
|
|
37
|
+
s.rdoc_options = ["--main", "README.txt"]
|
|
38
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
|
39
|
+
end
|
data/lib/drupal.rb
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# == SYNOPSIS:
|
|
4
|
+
#
|
|
5
|
+
# drupal [options] [arguments]
|
|
6
|
+
#
|
|
7
|
+
# == ARGUMENTS:
|
|
8
|
+
#
|
|
9
|
+
# create module Generates a module skeleton from an interactive wizard.
|
|
10
|
+
# todo list [total] Displays list of todo items or a total.
|
|
11
|
+
#
|
|
12
|
+
# == OPTIONS:
|
|
13
|
+
#
|
|
14
|
+
# -h, --help Display this help information.
|
|
15
|
+
# -V, --version Display version of the Drupal development tool.
|
|
16
|
+
#
|
|
17
|
+
# == EXAMPLES:
|
|
18
|
+
#
|
|
19
|
+
# Create a new module in the current directory.
|
|
20
|
+
# drupal create module my_module
|
|
21
|
+
#
|
|
22
|
+
# Create a new module in a specific directory.
|
|
23
|
+
# drupal create module my_module ./sites/all/modules
|
|
24
|
+
#
|
|
25
|
+
# View todo list for current directory.
|
|
26
|
+
# drupal todo list
|
|
27
|
+
#
|
|
28
|
+
# View todo list for multiple files or directories.
|
|
29
|
+
# drupal todo list ./sites/all/modules/mymodule
|
|
30
|
+
#
|
|
31
|
+
# View total todo items only.
|
|
32
|
+
# drupal todo list total ./sites/all/modules
|
|
33
|
+
|
|
34
|
+
require 'optparse'
|
|
35
|
+
require 'ostruct'
|
|
36
|
+
require File.dirname(__FILE__) + '/drupal/create_module'
|
|
37
|
+
require File.dirname(__FILE__) + '/drupal/todo_list'
|
|
38
|
+
require File.dirname(__FILE__) + '/drupal/install'
|
|
39
|
+
|
|
40
|
+
class Drupal
|
|
41
|
+
|
|
42
|
+
MAJOR = 0
|
|
43
|
+
MINOR = 0
|
|
44
|
+
TINY = 2
|
|
45
|
+
VERSION = [MAJOR, MINOR, TINY].join('.')
|
|
46
|
+
|
|
47
|
+
# Run the drupal development tool.
|
|
48
|
+
def run(arguments)
|
|
49
|
+
@arguments = arguments || []
|
|
50
|
+
@options = OpenStruct.new
|
|
51
|
+
abort 'Arguments required. Use --help for additional information.' if @arguments.empty?
|
|
52
|
+
parse_options
|
|
53
|
+
determine_handler
|
|
54
|
+
execute_handler
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Parse stdin for options.
|
|
58
|
+
def parse_options
|
|
59
|
+
opts = OptionParser.new
|
|
60
|
+
opts.on('-h', '--help') { output_help }
|
|
61
|
+
opts.on('-V', '--version') { output_version }
|
|
62
|
+
opts.parse!(@arguments)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Determine handler based on the current arguments.
|
|
66
|
+
def determine_handler
|
|
67
|
+
@handler = @arguments.shift.capitalize
|
|
68
|
+
while !@arguments.empty? && !is_handler(@handler) do
|
|
69
|
+
@handler << '_' + @arguments.shift.capitalize
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Execute the handler if it was found.
|
|
74
|
+
def execute_handler
|
|
75
|
+
abort 'Invalid command.' if !is_handler(@handler)
|
|
76
|
+
eval("Drupal::#{@handler}.new.run(@arguments)")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Check existance of a handler.
|
|
80
|
+
def is_handler(klass)
|
|
81
|
+
Drupal.const_defined?(klass)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Output help information.
|
|
85
|
+
def output_help
|
|
86
|
+
# TODO: utilize RDoc
|
|
87
|
+
puts <<-USAGE
|
|
88
|
+
|
|
89
|
+
SYNOPSIS:
|
|
90
|
+
|
|
91
|
+
drupal [options] [arguments]
|
|
92
|
+
|
|
93
|
+
ARGUMENTS:
|
|
94
|
+
|
|
95
|
+
create module <module_name> [dir] Generates a module skeleton from an interactive wizard. Current directory unless [dir] is specified.
|
|
96
|
+
todo list [total] Displays list of todo items or a total.
|
|
97
|
+
|
|
98
|
+
EXAMPLES:
|
|
99
|
+
|
|
100
|
+
Create a new module in the current directory.
|
|
101
|
+
drupal create module my_module
|
|
102
|
+
|
|
103
|
+
Create a new module in a specific directory.
|
|
104
|
+
drupal create module my_module ./sites/all/modules
|
|
105
|
+
|
|
106
|
+
View todo list for current directory.
|
|
107
|
+
drupal todo list
|
|
108
|
+
|
|
109
|
+
View todo list for multiple files or directories.
|
|
110
|
+
drupal todo list ./sites/all/modules/mymodule
|
|
111
|
+
|
|
112
|
+
View total todo items only.
|
|
113
|
+
drupal todo list total ./sites/all/modules
|
|
114
|
+
|
|
115
|
+
USAGE
|
|
116
|
+
exit
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Output version information.
|
|
120
|
+
def output_version
|
|
121
|
+
puts "Version #{Drupal::VERSION}"
|
|
122
|
+
exit
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
class Drupal
|
|
3
|
+
class Create_Module
|
|
4
|
+
|
|
5
|
+
# Create a module using the module builing wizard.
|
|
6
|
+
def run(arguments)
|
|
7
|
+
@arguments = arguments
|
|
8
|
+
@dir = @arguments[1] || '.' # TODO remove trailing slash, check validity, and existance
|
|
9
|
+
self.check_module_name
|
|
10
|
+
self.run_wizard
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Ensure module name is supplied and that it is
|
|
14
|
+
# formatted correctly as module names must be alphanumeric
|
|
15
|
+
# and must begin with a letter.
|
|
16
|
+
def check_module_name
|
|
17
|
+
case
|
|
18
|
+
when @arguments.empty?; puts 'Module name required.'; exit 3
|
|
19
|
+
when !@arguments[0].match(/^[a-z][\w]+/); puts 'Invalid module name.'; exit 4
|
|
20
|
+
else @module = @arguments[0]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Run module generation wizard.
|
|
25
|
+
def run_wizard
|
|
26
|
+
# TODO create self.log() with padding to even output
|
|
27
|
+
# Info
|
|
28
|
+
@author = self.ask('What is your name?:')
|
|
29
|
+
@link = self.ask('What is the URI to your companies website?:')
|
|
30
|
+
@email = self.ask('What is your email?:')
|
|
31
|
+
@module_name = self.ask('Enter a human readable name for your module:')
|
|
32
|
+
@module_description = self.ask('Enter a short description of your module:')
|
|
33
|
+
@module_dependencies = self.ask('Enter a list of dependencies for your module:', true)
|
|
34
|
+
# Hooks
|
|
35
|
+
puts self.list_templates('Hooks:', 'hooks')
|
|
36
|
+
@hooks = self.ask('Which hooks would you like to implement?:', true)
|
|
37
|
+
# Files
|
|
38
|
+
puts self.list_templates('Files:', 'txt')
|
|
39
|
+
@files = self.ask('Which additional files would you like to include?:', true)
|
|
40
|
+
# Dirs
|
|
41
|
+
puts "\nCommon directories:"
|
|
42
|
+
puts ['js', 'images', 'css'].collect{ |d| " - " << d }
|
|
43
|
+
@dirs = self.ask('Which directories would you like to create?:', true)
|
|
44
|
+
# Finish
|
|
45
|
+
self.create_tokens
|
|
46
|
+
self.create_hook_weights
|
|
47
|
+
self.create_module
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Create global tokens.
|
|
51
|
+
def create_tokens
|
|
52
|
+
@tokens = {
|
|
53
|
+
:module => @module,
|
|
54
|
+
:link => @link,
|
|
55
|
+
:email => @email,
|
|
56
|
+
:author => @author,
|
|
57
|
+
:module_name => @module_name,
|
|
58
|
+
:module_description => @module_description,
|
|
59
|
+
:module_dependencies => @module_dependencies,
|
|
60
|
+
}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Register hook weights
|
|
64
|
+
def create_hook_weights
|
|
65
|
+
@hook_weights = [
|
|
66
|
+
'perm',
|
|
67
|
+
'cron',
|
|
68
|
+
'boot',
|
|
69
|
+
'init',
|
|
70
|
+
'menu',
|
|
71
|
+
'schema',
|
|
72
|
+
'theme',
|
|
73
|
+
'form_alter',
|
|
74
|
+
'block',
|
|
75
|
+
]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Create module from wizard results.
|
|
79
|
+
def create_module
|
|
80
|
+
puts "\n... Creating module '#{@module}' in '#{@dir}'"
|
|
81
|
+
# TODO: map hooks to specific order...usort equiv
|
|
82
|
+
# Base directory
|
|
83
|
+
create_dir("#{@module}")
|
|
84
|
+
self.create_module_dirs
|
|
85
|
+
self.create_module_files
|
|
86
|
+
self.create_module_file
|
|
87
|
+
self.create_module_install_file
|
|
88
|
+
self.create_module_info_file
|
|
89
|
+
puts 'Module created :)'
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Create directories.
|
|
93
|
+
def create_module_dirs
|
|
94
|
+
@dirs.each{ |dir| create_dir("#{@module}/#{dir}") }
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Create file templates.
|
|
98
|
+
def create_module_files
|
|
99
|
+
@files.each do |file|
|
|
100
|
+
filepath = "#{file.upcase}.txt"
|
|
101
|
+
create_file(filepath)
|
|
102
|
+
append_template(filepath, "txt/#{file}", @tokens)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Create .module file.
|
|
107
|
+
def create_module_file
|
|
108
|
+
create_file("#{@module}.module", "<?php\n")
|
|
109
|
+
append_template("#{@module}.module", 'comments/file', @tokens)
|
|
110
|
+
append_template("#{@module}.module", 'comments/large', {'title' => 'Hook Implementations'})
|
|
111
|
+
for hook in @hook_weights
|
|
112
|
+
if @hooks.include?(hook)
|
|
113
|
+
append_template("#{@module}.module", "hooks/#{hook}", @tokens) unless hook.match /^install|schema/
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Create .install file.
|
|
119
|
+
def create_module_install_file
|
|
120
|
+
if @hooks.include?('schema') || @hooks.include?('schema')
|
|
121
|
+
create_file("#{@module}.install", "<?php\n")
|
|
122
|
+
append_template("#{@module}.install", 'comments/file', @tokens)
|
|
123
|
+
@hooks.each do |hook|
|
|
124
|
+
append_template("#{@module}.install", "hooks/#{hook}", @tokens) if hook.match /^install|schema/
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Create info file.
|
|
130
|
+
def create_module_info_file
|
|
131
|
+
contents = '; $Id$'
|
|
132
|
+
contents << "\nname = #{@module_name}"
|
|
133
|
+
contents << "\ndescription = #{@module_description}"
|
|
134
|
+
contents << "\ncore = 6.x"
|
|
135
|
+
@module_dependencies.each do |dependency|
|
|
136
|
+
contents << "\ndependencies[] = #{dependency}"
|
|
137
|
+
end
|
|
138
|
+
create_file("#{@module}.info", contents)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Create a new directory.
|
|
142
|
+
def create_dir(dir)
|
|
143
|
+
dir = "#{@dir}/#{dir}"
|
|
144
|
+
puts "... Creating directory '#{dir}'"
|
|
145
|
+
Dir.mkdir(dir)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Create a new file.
|
|
149
|
+
def create_file(filepath, contents = '')
|
|
150
|
+
filepath = "#{@dir}/#{@module}/#{filepath}"
|
|
151
|
+
puts "... Creating file '#{filepath}'"
|
|
152
|
+
File.open(filepath, 'w') do |f|
|
|
153
|
+
f.write contents
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Append a tokenized template template to a file.
|
|
158
|
+
def append_template(filepath, template, tokens = {})
|
|
159
|
+
# TODO: ensure template exists
|
|
160
|
+
# TODO: is \n included with STDIN?
|
|
161
|
+
_template = template
|
|
162
|
+
filepath = "#{@dir}/#{@module}/#{filepath}"
|
|
163
|
+
template = File.dirname(__FILE__) + "/templates/#{template}"
|
|
164
|
+
puts "... Adding template '#{_template}' to '#{filepath}'"
|
|
165
|
+
contents = File.read(template)
|
|
166
|
+
tokens.each_pair do |token, value|
|
|
167
|
+
if value.class == String && contents.include?("[#{token}]")
|
|
168
|
+
contents.gsub!(/\[#{token}\]/, value)
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
File.open(filepath, 'a') do |f|
|
|
172
|
+
f.write contents
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Prompt user for input
|
|
177
|
+
def ask(question, list = false)
|
|
178
|
+
puts "\n" << question
|
|
179
|
+
# TODO: support 'all'
|
|
180
|
+
# TODO: why is gets not working?
|
|
181
|
+
# TODO: not catching exception when CTRL+C ?
|
|
182
|
+
begin
|
|
183
|
+
case list
|
|
184
|
+
when true; STDIN.gets.split
|
|
185
|
+
when false; STDIN.gets.gsub!(/\n/, '')
|
|
186
|
+
end
|
|
187
|
+
rescue => e
|
|
188
|
+
puts ':)'
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# List templates available of a certain type.
|
|
193
|
+
def list_templates(title, type)
|
|
194
|
+
"\n" << title << self.get_templates(type).collect{ |t| "\n - " << File.basename(t) }.join
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# Get array of templates of a certain type.
|
|
198
|
+
def get_templates(type)
|
|
199
|
+
Dir[File.dirname(__FILE__) + '/templates/' << type << '/*']
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
require 'open-uri'
|
|
3
|
+
|
|
4
|
+
class Drupal
|
|
5
|
+
class Install
|
|
6
|
+
|
|
7
|
+
# Attempt to download core installation or module.
|
|
8
|
+
def run(arguments)
|
|
9
|
+
@project = arguments[0]
|
|
10
|
+
@dest = arguments[1] || '.'
|
|
11
|
+
abort 'Project name required (core | <project>).' if arguments.empty?
|
|
12
|
+
print "Destination '#{@dest}' is not empty, are you sure you want continue installation? (yes|no): " unless destination_empty?
|
|
13
|
+
confirmation = STDIN.gets unless destination_empty?
|
|
14
|
+
abort 'Installation aborted.' unless confirmation =~ /y|yes/
|
|
15
|
+
check_core
|
|
16
|
+
install_project if project_exists?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def debug(message)
|
|
20
|
+
puts '... ' + message
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Check if the destination is empty.
|
|
24
|
+
def destination_empty?
|
|
25
|
+
Dir['*'].length == 0
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Allow users to type 'core' instead of 'drupal install drupal'
|
|
29
|
+
def check_core
|
|
30
|
+
@project = 'drupal' if @project =~ /^core|drupal$/
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Determine if the project passed actually exists as a module.
|
|
34
|
+
def project_exists?
|
|
35
|
+
debug 'Locating project page'
|
|
36
|
+
if !uri_available?("http://drupal.org/project/#{@project}")
|
|
37
|
+
abort "Failed to find #{@project}."
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Check if a uri is available.
|
|
42
|
+
def uri_available?(uri)
|
|
43
|
+
open(uri) rescue false
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Install project.
|
|
47
|
+
def install_project
|
|
48
|
+
debug "Located #{@project} page"
|
|
49
|
+
@markup = open("http://drupal.org/project/#{@project}") { |f| f.read }
|
|
50
|
+
@markup.match /#{@project}-6\.x-[\d]\.[\d](?:\.\d)?(?:-\w+)?\.tar\.gz/
|
|
51
|
+
# TODO: make sure markup works..
|
|
52
|
+
# TODO: make sure match works..
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -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,37 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of hook_schema().
|
|
4
|
+
*/
|
|
5
|
+
function [module]_schema() {
|
|
6
|
+
$schema = array();
|
|
7
|
+
|
|
8
|
+
$schema['[module]'] = array(
|
|
9
|
+
'description' => t('Table description here.'),
|
|
10
|
+
'fields' => array(
|
|
11
|
+
'id' => array(
|
|
12
|
+
'description' => t('Primary identifier.'),
|
|
13
|
+
'type' => 'serial',
|
|
14
|
+
'unsigned' => TRUE,
|
|
15
|
+
'not null' => TRUE),
|
|
16
|
+
'status' => array(
|
|
17
|
+
'description' => t('Status. 0 = unpublished, 1 = published.'),
|
|
18
|
+
'type' => 'int',
|
|
19
|
+
'size' => 'tiny',
|
|
20
|
+
'not null' => FALSE,
|
|
21
|
+
'default' => 0),
|
|
22
|
+
'created' => array(
|
|
23
|
+
'description' => t('The Unix timestamp when the row was created.'),
|
|
24
|
+
'type' => 'int',
|
|
25
|
+
'not null' => TRUE,
|
|
26
|
+
'default' => 0),
|
|
27
|
+
),
|
|
28
|
+
'indexes' => array(
|
|
29
|
+
'status' => array('status'),
|
|
30
|
+
'created' => array('created'),
|
|
31
|
+
'id_status' => array('id', 'status'),
|
|
32
|
+
),
|
|
33
|
+
'primary key' => array('id'),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return $schema;
|
|
37
|
+
}
|
|
@@ -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,40 @@
|
|
|
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
|
+
file.each_line do |line|
|
|
24
|
+
matches = line.match /(?:#|\/\/|\/\*)[\s]*todo:?[\s]*(.+)$/i
|
|
25
|
+
items << matches[1] unless matches.nil? || matches.length <= 0
|
|
26
|
+
@total += 1 unless matches.nil? || matches.length <= 0
|
|
27
|
+
end
|
|
28
|
+
puts "\n" + filepath unless items.empty? || @total_only == true
|
|
29
|
+
items.each{ |item| puts " - #{item}" } unless @total_only == true
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Parse directory for todo items.
|
|
34
|
+
def parse_dir(dir)
|
|
35
|
+
Dir["#{dir == '.' ? '.' : dir}/**/*"].each do |file|
|
|
36
|
+
parse_file(file) if File.file?(file)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/test/test_drupal.rb
ADDED
|
File without changes
|
metadata
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: visionmedia-drupal
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- tj@vision-media.ca
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2008-09-29 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Drupal is an open source Ruby development tool allowing developers to quickly generate and manage Drupal modules.
|
|
17
|
+
email: tj@vision-media.ca
|
|
18
|
+
executables:
|
|
19
|
+
- drupal
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- History.txt
|
|
24
|
+
- Manifest.txt
|
|
25
|
+
- README.txt
|
|
26
|
+
files:
|
|
27
|
+
- History.txt
|
|
28
|
+
- Manifest.txt
|
|
29
|
+
- README.txt
|
|
30
|
+
- Rakefile
|
|
31
|
+
- drupal.gemspec
|
|
32
|
+
- lib/drupal.rb
|
|
33
|
+
- lib/drupal/create_module.rb
|
|
34
|
+
- lib/drupal/todo_list.rb
|
|
35
|
+
- lib/drupal/install.rb
|
|
36
|
+
- lib/drupal/templates/comments/file
|
|
37
|
+
- lib/drupal/templates/comments/large
|
|
38
|
+
- lib/drupal/templates/hooks/block
|
|
39
|
+
- lib/drupal/templates/hooks/boot
|
|
40
|
+
- lib/drupal/templates/hooks/cron
|
|
41
|
+
- lib/drupal/templates/hooks/form_alter
|
|
42
|
+
- lib/drupal/templates/hooks/init
|
|
43
|
+
- lib/drupal/templates/hooks/menu
|
|
44
|
+
- lib/drupal/templates/hooks/perm
|
|
45
|
+
- lib/drupal/templates/hooks/schema
|
|
46
|
+
- lib/drupal/templates/hooks/theme
|
|
47
|
+
- lib/drupal/templates/txt/changelog
|
|
48
|
+
- lib/drupal/templates/txt/readme
|
|
49
|
+
- bin/drupal
|
|
50
|
+
has_rdoc: true
|
|
51
|
+
homepage: http://vision-media.ca/resources/drupal/drupal-module-builder-gem
|
|
52
|
+
post_install_message:
|
|
53
|
+
rdoc_options:
|
|
54
|
+
- --main
|
|
55
|
+
- README.txt
|
|
56
|
+
require_paths:
|
|
57
|
+
- lib
|
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: "0"
|
|
63
|
+
version:
|
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: "0"
|
|
69
|
+
version:
|
|
70
|
+
requirements: []
|
|
71
|
+
|
|
72
|
+
rubyforge_project:
|
|
73
|
+
rubygems_version: 1.2.0
|
|
74
|
+
signing_key:
|
|
75
|
+
specification_version: 2
|
|
76
|
+
summary: Drupal development kit
|
|
77
|
+
test_files:
|
|
78
|
+
- test/test_drupal.rb
|