berkes-drupal.rb 0.0.6

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 ADDED
@@ -0,0 +1,35 @@
1
+ === 0.0.6 / 2008-10-16
2
+
3
+ * 1 Minor Feature:
4
+
5
+ * Added hook_install() support
6
+
7
+ === 0.0.5 / 2008-10-06
8
+
9
+ * 1 Minor Fix:
10
+
11
+ * Todo list was not parsing items starting with '@' in @todo
12
+
13
+ === 0.0.4 / 2008-10-03
14
+
15
+ * 1 Major Feature:
16
+
17
+ * Installer allows lists of projects 'err,ac,devel'
18
+
19
+ === 0.0.3 / 2008-10-03
20
+
21
+ * 1 Major Feature:
22
+
23
+ * Installer for Drupal projects
24
+
25
+ === 0.0.2 / 2008-10-02
26
+
27
+ * 2 Bug Fixes:
28
+
29
+ * Executable
30
+ * Fixed template filepath errors
31
+
32
+ === 0.0.1 / 2008-09-27
33
+
34
+ * Initial release
35
+
data/Manifest.txt ADDED
@@ -0,0 +1,23 @@
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/install
15
+ lib/drupal/templates/hooks/cron
16
+ lib/drupal/templates/hooks/form_alter
17
+ lib/drupal/templates/hooks/init
18
+ lib/drupal/templates/hooks/menu
19
+ lib/drupal/templates/hooks/perm
20
+ lib/drupal/templates/hooks/schema
21
+ lib/drupal/templates/hooks/theme
22
+ lib/drupal/templates/txt/changelog
23
+ lib/drupal/templates/txt/readme
data/README.txt ADDED
@@ -0,0 +1,94 @@
1
+ = drupal
2
+
3
+ http://berkes.github.com/drupal.rb/
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
+ install <core | project> [dir] Install a Drupal project or core itself to [dir]
23
+
24
+ == OPTIONS:
25
+
26
+ -h, --help Display this help information.
27
+ -V, --version Display version of the Drupal development tool.
28
+
29
+ == EXAMPLES:
30
+
31
+ Create a new module in the current directory.
32
+ drupal create module my_module
33
+
34
+ Create a new module in a specific directory.
35
+ drupal create module my_module ./sites/all/modules
36
+
37
+ View todo list for current directory.
38
+ drupal todo list
39
+
40
+ View todo list for multiple files or directories.
41
+ drupal todo list ./sites/all/modules/mymodule
42
+
43
+ View total todo items only.
44
+ drupal todo list total ./sites/all/modules
45
+
46
+ == TODO:
47
+
48
+ * Remove ':' from todo list items
49
+ * Add formatted help option
50
+ * Support versions for installer
51
+ * Support version prompt for project installation
52
+ * Support installing a list from file(s) so that devs may have lists of core modules they use
53
+ * Add hook dependencies
54
+ * Add installer for jQuery plugins?
55
+ * Add graceful error handling
56
+ * Add / refactor tests, using rspec
57
+ * Refactor / encapsulate entire project / make extendable
58
+
59
+ == AUTHOR:
60
+
61
+ Original:
62
+ TJ Holowaychuk
63
+ tj@vision-media.ca
64
+ http://vision-media.ca
65
+
66
+ Current Maintainer:
67
+ Bèr Kessels
68
+ ber@webschuur.com
69
+ http://webschuur.com
70
+
71
+ == LICENSE:
72
+
73
+ (The MIT License)
74
+
75
+ Copyright (c) 2008 FIX
76
+
77
+ Permission is hereby granted, free of charge, to any person obtaining
78
+ a copy of this software and associated documentation files (the
79
+ 'Software'), to deal in the Software without restriction, including
80
+ without limitation the rights to use, copy, modify, merge, publish,
81
+ distribute, sublicense, and/or sell copies of the Software, and to
82
+ permit persons to whom the Software is furnished to do so, subject to
83
+ the following conditions:
84
+
85
+ The above copyright notice and this permission notice shall be
86
+ included in all copies or substantial portions of the Software.
87
+
88
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
89
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
90
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
91
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
92
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
93
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
94
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
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
17
+
18
+ desc 'Run tests.'
19
+ task :test do
20
+ sh "ruby " + File.dirname(__FILE__) + '/test/test_drupal.rb' + ' -r tk'
21
+ end
data/bin/drupal ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'drupal'
4
+ Drupal.new.run(ARGV)
data/drupal.rb.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "drupal.rb"
3
+ s.version = "0.0.6"
4
+ s.date = "2008-10-16"
5
+ s.summary = "Drupal development kit"
6
+ s.email = "ber@webschuur.com"
7
+ s.homepage = "http://berkes.github.com/drupal.rb/"
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", "ber@webschuur.com"]
12
+ s.files = ["History.txt",
13
+ "Manifest.txt",
14
+ "README.txt",
15
+ "Rakefile",
16
+ "drupal.rb.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/install",
26
+ "lib/drupal/templates/hooks/cron",
27
+ "lib/drupal/templates/hooks/form_alter",
28
+ "lib/drupal/templates/hooks/init",
29
+ "lib/drupal/templates/hooks/menu",
30
+ "lib/drupal/templates/hooks/perm",
31
+ "lib/drupal/templates/hooks/schema",
32
+ "lib/drupal/templates/hooks/theme",
33
+ "lib/drupal/templates/txt/changelog",
34
+ "lib/drupal/templates/txt/readme",
35
+ "bin/drupal"]
36
+ s.executables = ["drupal"]
37
+ s.test_files = ["test/test_drupal.rb", "test/test_install.rb", "test/test_create_module.rb", "test/test_todo_list.rb"]
38
+ s.rdoc_options = ["--main", "README.txt"]
39
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
40
+ end
@@ -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
+ 'install',
72
+ 'schema',
73
+ 'theme',
74
+ 'form_alter',
75
+ 'block',
76
+ ]
77
+ end
78
+
79
+ # Create module from wizard results.
80
+ def create_module
81
+ puts "\n... Creating module '#{@module}' in '#{@dir}'"
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,95 @@
1
+
2
+ require 'zlib'
3
+ require 'net/http'
4
+
5
+ class Drupal
6
+ class Install
7
+
8
+ # Attempt to download core installation or module.
9
+ def run(arguments)
10
+ @project = arguments[0]
11
+ @dest = arguments[1] || '.'
12
+ abort "Destination #{@dest} is not a directory." unless File.directory?(@dest)
13
+ abort 'Project name required (core | <project>).' if arguments.empty?
14
+ install_projects
15
+ end
16
+
17
+ def debug(message)
18
+ puts '... ' + message
19
+ end
20
+
21
+ # Install single project or iterate lists.
22
+ def install_projects
23
+ if @project.include? ','
24
+ projects = @project.split ','
25
+ projects.each do |p|
26
+ @project = p
27
+ check_core
28
+ install_project
29
+ puts
30
+ end
31
+ else
32
+ check_core
33
+ install_project
34
+ end
35
+ end
36
+
37
+ # Check if the destination is empty.
38
+ def destination_empty?
39
+ Dir['*'].length == 0
40
+ end
41
+
42
+ # Allow users to type 'core' instead of 'drupal install drupal'
43
+ def check_core
44
+ @project = 'drupal' if @project =~ /^core|drupal$/
45
+ end
46
+
47
+ # Check if a uri is available.
48
+ def uri_available?(uri)
49
+ open(uri) rescue false
50
+ end
51
+
52
+ # Install project.
53
+ def install_project
54
+ debug "Locating #{@project} page"
55
+ # Locate tarball from project page
56
+ begin
57
+ response = Net::HTTP.get_response(URI.parse("http://drupal.org/project/#{@project}"))
58
+ @markup = response.body
59
+ # TODO: check 404
60
+ debug 'Located the project page'
61
+ rescue
62
+ puts 'Failed to request page'
63
+ end
64
+ @markup.match /(#{@project}-6(?:.*?)\.gz)/
65
+ @tarball = $1
66
+ @tarpath = File.expand_path("#{@dest}/#{@tarball}")
67
+ abort "Failed to find Drupal 6 tar of #{@project}" if @tarball.nil?
68
+ debug "Found tarball #{@tarball}"
69
+
70
+ # Fetch tarball
71
+ begin
72
+ response = Net::HTTP.get_response(URI.parse("http://ftp.drupal.org/files/projects/#{@tarball}"))
73
+ File.open(@tarpath, 'w') do |f|
74
+ f.write response.body
75
+ end
76
+ debug "Copied tarball to #{@tarpath}"
77
+ rescue
78
+ abort "Failed to copy remote tarball #{@tarball}"
79
+ end
80
+
81
+ # Extract tarball
82
+ @pwd = Dir.getwd
83
+ Dir.chdir File.dirname(@tarpath) and debug "Changed cwd to #{File.dirname(@tarpath)}" unless @dest == '.'
84
+ Kernel.system "tar -xf #{@tarpath}" rescue abort "Failed to extract #{@tarpath}"
85
+ Dir.chdir @pwd and debug "Reverted cwd back to #{@pwd}" unless @dest == '.'
86
+
87
+ # Remove tarball
88
+ Kernel.system "rm #{@tarpath}" rescue abort "Failed to remove #{@tarpath}"
89
+
90
+ # Installation complete
91
+ debug "Project installed to #{File.dirname(@tarpath)}" unless @dest == '.'
92
+ debug 'Installation complete'
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,9 @@
1
+ // $Id$
2
+
3
+ /**
4
+ * @file
5
+ * [module_description]
6
+ * @author [author] <[email]>
7
+ * @link [link]
8
+ * @package [module]
9
+ */
@@ -0,0 +1,6 @@
1
+
2
+ /* -----------------------------------------------------------------
3
+
4
+ [title]
5
+
6
+ ------------------------------------------------------------------ */
@@ -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,7 @@
1
+
2
+ /**
3
+ * Implementation of hook_boot().
4
+ */
5
+ function [module]_boot() {
6
+
7
+ }
@@ -0,0 +1,7 @@
1
+
2
+ /**
3
+ * Implementation of hook_cron().
4
+ */
5
+ function [module]_cron() {
6
+
7
+ }
@@ -0,0 +1,11 @@
1
+
2
+ /**
3
+ * Implementation of hook_form_alter().
4
+ */
5
+ function [module]_form_alter(&$form, $form_state, $form_id) {
6
+ switch($form_id) {
7
+ case '':
8
+ // @todo: do something
9
+ break;
10
+ }
11
+ }
@@ -0,0 +1,7 @@
1
+
2
+ /**
3
+ * Implementation of hook_init().
4
+ */
5
+ function [module]_init() {
6
+
7
+ }
@@ -0,0 +1,7 @@
1
+
2
+ /**
3
+ * Implementation of hook_install().
4
+ */
5
+ function [module]_install() {
6
+ drupal_install_schema('[module]');
7
+ }
@@ -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,7 @@
1
+
2
+ /**
3
+ * Implementation of hook_perm().
4
+ */
5
+ function [module]_perm() {
6
+ return array('administer [module]');
7
+ }
@@ -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,11 @@
1
+
2
+ /**
3
+ * Implementation of hook_theme().
4
+ */
5
+ function [module]_theme($existing, $type, $theme, $path) {
6
+ return array(
7
+ 'forum_topic_navigation' => array(
8
+ 'arguments' => array('node' => NULL),
9
+ ),
10
+ );
11
+ }
@@ -0,0 +1,9 @@
1
+
2
+ $Id$
3
+
4
+
5
+ -------------------------------------------------------------------------------
6
+ [module] 6.4-1.0, YYYY-MM-DD
7
+ -------------------------------------------------------------------------------
8
+
9
+ - Initial release
@@ -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/lib/drupal.rb ADDED
@@ -0,0 +1,148 @@
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] Install Drupal project(s) to [dir] or the current directory.
12
+ #
13
+ # == OPTIONS:
14
+ #
15
+ # -h, --help Display this help information.
16
+ # -V, --version Display version of the Drupal development tool.
17
+ #
18
+ # == EXAMPLES:
19
+ #
20
+ # Create a new module in the current directory.
21
+ # drupal create module my_module
22
+ #
23
+ # Create a new module in a specific directory.
24
+ # drupal create module my_module ./sites/all/modules
25
+ #
26
+ # View todo list for current directory.
27
+ # drupal todo list
28
+ #
29
+ # View todo list for multiple files or directories.
30
+ # drupal todo list ./sites/all/modules/mymodule
31
+ #
32
+ # View total todo items only.
33
+ # drupal todo list total ./sites/all/modules
34
+ #
35
+ # Install a module to the modules folder in my new installation (from drupal root)
36
+ # drupal install devel ./sites/all/modules
37
+ #
38
+ # Install a module when in the 'modules directory
39
+ # drupal install devel
40
+ #
41
+ # Install several modules to the modules folder
42
+ # drupal install devel,pathauto,err,ac ./sites/all/modules
43
+ #
44
+
45
+ require 'optparse'
46
+ require 'ostruct'
47
+ require File.dirname(__FILE__) + '/drupal/create_module'
48
+ require File.dirname(__FILE__) + '/drupal/todo_list'
49
+ require File.dirname(__FILE__) + '/drupal/install'
50
+
51
+ class Drupal
52
+
53
+ MAJOR = 0
54
+ MINOR = 0
55
+ TINY = 6
56
+ VERSION = [MAJOR, MINOR, TINY].join('.')
57
+
58
+ # Run the drupal development tool.
59
+ def run(arguments)
60
+ @arguments = arguments || []
61
+ @options = OpenStruct.new
62
+ abort 'Arguments required. Use --help for additional information.' if @arguments.empty?
63
+ parse_options
64
+ determine_handler
65
+ execute_handler
66
+ end
67
+
68
+ # Parse stdin for options.
69
+ def parse_options
70
+ opts = OptionParser.new
71
+ opts.on('-h', '--help') { output_help }
72
+ opts.on('-V', '--version') { output_version }
73
+ opts.parse!(@arguments)
74
+ end
75
+
76
+ # Determine handler based on the current arguments.
77
+ def determine_handler
78
+ @handler = @arguments.shift.capitalize
79
+ while !@arguments.empty? && !is_handler(@handler) do
80
+ @handler << '_' + @arguments.shift.capitalize
81
+ end
82
+ end
83
+
84
+ # Execute the handler if it was found.
85
+ def execute_handler
86
+ abort 'Invalid command.' if !is_handler(@handler)
87
+ eval("Drupal::#{@handler}.new.run(@arguments)")
88
+ end
89
+
90
+ # Check existance of a handler.
91
+ def is_handler(klass)
92
+ Drupal.const_defined?(klass)
93
+ end
94
+
95
+ # Output help information.
96
+ def output_help
97
+ # TODO: utilize RDoc
98
+ puts <<-USAGE
99
+
100
+ SYNOPSIS:
101
+
102
+ drupal [options] [arguments]
103
+
104
+ ARGUMENTS:
105
+
106
+ create module <module_name> [dir] Generates a module skeleton from an interactive wizard. Current directory unless [dir] is specified.
107
+ todo list [total] Displays list of todo items or a total.
108
+ install <core | project> [dir] Install a Drupal project or core itself to [dir]
109
+
110
+ EXAMPLES:
111
+
112
+ Create a new module in the current directory.
113
+ drupal create module my_module
114
+
115
+ Create a new module in a specific directory.
116
+ drupal create module my_module ./sites/all/modules
117
+
118
+ View todo list for current directory.
119
+ drupal todo list
120
+
121
+ View todo list for multiple files or directories.
122
+ drupal todo list ./sites/all/modules/mymodule
123
+
124
+ View total todo items only.
125
+ drupal todo list total ./sites/all/modules
126
+
127
+ Install drupal core to the current directory.
128
+ drupal install core
129
+
130
+ Install a module to the modules folder in my new installation (from drupal root)
131
+ drupal install devel ./sites/all/modules
132
+
133
+ Install a module when in the 'modules directory
134
+ drupal install devel
135
+
136
+ USAGE
137
+ exit
138
+ end
139
+
140
+ # Output version information.
141
+ def output_version
142
+ puts "Version #{Drupal::VERSION}"
143
+ exit
144
+ end
145
+ end
146
+
147
+
148
+
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,6 @@
1
+
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/drupal.rb'
4
+ require File.dirname(__FILE__) + '/test_install.rb'
5
+ require File.dirname(__FILE__) + '/test_create_module.rb'
6
+ require File.dirname(__FILE__) + '/test_todo_list.rb'
@@ -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
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: berkes-drupal.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - tj@vision-media.ca
8
+ - ber@webschuur.com
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-10-16 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Drupal is an open source Ruby development tool allowing developers to quickly generate and manage Drupal modules.
18
+ email: ber@webschuur.com
19
+ executables:
20
+ - drupal
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - History.txt
25
+ - Manifest.txt
26
+ - README.txt
27
+ files:
28
+ - History.txt
29
+ - Manifest.txt
30
+ - README.txt
31
+ - Rakefile
32
+ - drupal.rb.gemspec
33
+ - lib/drupal.rb
34
+ - lib/drupal/create_module.rb
35
+ - lib/drupal/todo_list.rb
36
+ - lib/drupal/install.rb
37
+ - lib/drupal/templates/comments/file
38
+ - lib/drupal/templates/comments/large
39
+ - lib/drupal/templates/hooks/block
40
+ - lib/drupal/templates/hooks/boot
41
+ - lib/drupal/templates/hooks/install
42
+ - lib/drupal/templates/hooks/cron
43
+ - lib/drupal/templates/hooks/form_alter
44
+ - lib/drupal/templates/hooks/init
45
+ - lib/drupal/templates/hooks/menu
46
+ - lib/drupal/templates/hooks/perm
47
+ - lib/drupal/templates/hooks/schema
48
+ - lib/drupal/templates/hooks/theme
49
+ - lib/drupal/templates/txt/changelog
50
+ - lib/drupal/templates/txt/readme
51
+ - bin/drupal
52
+ has_rdoc: true
53
+ homepage: http://berkes.github.com/drupal.rb/
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --main
57
+ - README.txt
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.2.0
76
+ signing_key:
77
+ specification_version: 2
78
+ summary: Drupal development kit
79
+ test_files:
80
+ - test/test_drupal.rb
81
+ - test/test_install.rb
82
+ - test/test_create_module.rb
83
+ - test/test_todo_list.rb