listrophy-suprails 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,41 @@
1
+ # Copyright 2008 Bradley Grzesiak
2
+ # This file is part of Suprails.
3
+ #
4
+ # Suprails is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # Suprails is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with Suprails. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ Suprails
18
+ ========
19
+
20
+ This project is intended to be a replacement for the "rails" command. It
21
+ does not replace the rails framework but rather provides a starting point
22
+ for a rails application far beyond what the "rails" command provides.
23
+ During execution, in fact, the suprails command calls the rails command.
24
+
25
+ How it works
26
+ ============
27
+
28
+ Suprails is unlike most other "Rails plus other stuff" projects out there.
29
+ Instead of me, the Suprails author, deciding what you should have in your rails
30
+ app, you get to decide. In addition, any time you execute Suprails, you have
31
+ the option to update any gems that would otherwise be out-of-date.
32
+
33
+ Installation
34
+ ============
35
+
36
+ TBD
37
+
38
+ Bugs
39
+ ====
40
+
41
+ 0.0.0 - Initial readme. No code.
data/TODO ADDED
@@ -0,0 +1,29 @@
1
+ 13-Oct-08
2
+ ---------
3
+ Command list is tentatively:
4
+
5
+ sources "foldername"
6
+ rails
7
+ freeze
8
+ gems.config [:development|:test|:production] [ :gemname1 [, "gemname2" [...]]]
9
+ gems.update [ "gemname1" [, :gemname2 [...]]]
10
+ gems.unpack
11
+ plugin "pluginlocation"
12
+ generate "generator" [ :optional_argument [, "optional_argument2" [...]]]
13
+ folder "foldername"
14
+ file "sourcefile", "destfile"
15
+ delete "filename"
16
+ gpl
17
+ db.(development|test|production).(adapter|encoding|database|username|password|host) "value"
18
+ db.create
19
+ rake "rake-task"
20
+ git
21
+ svn
22
+ (facet-name)
23
+ (facet-name).(cmd) [ :optional_argument1 [, "optional_argument2" [...]]]
24
+
25
+ =========
26
+
27
+ courtesy of nice_burger on irc.freenode.net#rubyonrails
28
+
29
+ I18n,globalize2 for that. map.root in route.db to welcome or something. install haml, if only to get sass. freeze rails, action_mailer stuff for restful_auth, exception_notifier is good, capify, shoulda for tests, app_config plugin, put something nice in README, set up on github (ssh keys stuff to worry about). um, for starters.
data/bin/suprails ADDED
@@ -0,0 +1,70 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # Suprails: The customizable wrapper to the rails command
4
+ #
5
+ # Copyright 2008 Bradley Grzesiak
6
+ # This file is part of Suprails.
7
+ #
8
+ # Suprails is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation, either version 3 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # Suprails is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with Suprails. If not, see <http://www.gnu.org/licenses/>.
20
+ #
21
+
22
+ require File.dirname(__FILE__) + '/../lib/suprails'
23
+ opts = ARGV
24
+ SUPRAILS_VERSION = 0.1
25
+
26
+ def is_setup?
27
+ File.exists?(File.expand_path('~/.suprails'))
28
+ end
29
+
30
+ def setup_suprails
31
+ Dir.mkdir(File.expand_path('~/.suprails'))
32
+ Dir.mkdir(File.expand_path('~/.suprails/sources'))
33
+ Dir.mkdir(File.expand_path('~/.suprails/facets'))
34
+ require 'ftools'
35
+ config_source = File.expand_path(File.dirname(__FILE__) + '/../.suprails.example')
36
+ config_dest = File.expand_path('~/.suprails/config')
37
+ File.copy(config_source, config_dest, false)
38
+ Dir[File.dirname(__FILE__) + '/../facets/*.rb'].each do |f|
39
+ File.copy(f, File.expand_path('~/.suprails/facets/'), false)
40
+ end
41
+ end
42
+
43
+ # Does the ~/.suprails folder exist?
44
+ if !is_setup?
45
+ setup_suprails
46
+ exit
47
+ end
48
+
49
+ if opts.length == 0
50
+ puts 'You must provide a Rails Application Name'
51
+ else
52
+ # If options include -v or --version, print the version and exit
53
+ if opts.inject(false) {|memo, x| memo || %w{-v --version}.include?(x)}
54
+ puts SUPRAILS_VERSION
55
+ exit
56
+ end
57
+
58
+ # setup the config file, using ~/.suprails/config as default
59
+ config = opts.index('-c') || opts.index('--config') || '~/.suprails/config'
60
+ if config.is_a? Fixnum
61
+ opts.delete_at(config)
62
+ config = opts.delete_at(config)
63
+ end
64
+
65
+ if opts.first =~ /^[a-zA-Z0-9]+/
66
+ Suprails.new(opts.shift).create_project
67
+ else
68
+ puts 'Invalid Application Name. Must start with alphanumeric character!'
69
+ end
70
+ end
data/facets/haml.rb ADDED
@@ -0,0 +1,28 @@
1
+ #
2
+ # Haml Facet for Suprails
3
+ # Copyright 2008 Bradley Grzesiak
4
+ # This file is part of Suprails.
5
+ #
6
+ # Suprails is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Suprails is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Suprails. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ Facet.define "haml" do
21
+ author "Bradley Grzesiak"
22
+ version "0.1"
23
+
24
+ def go app_name
25
+ puts 'Running haml'
26
+ `haml --rails #{app_name}`
27
+ end
28
+ end
data/lib/db.rb ADDED
@@ -0,0 +1,73 @@
1
+ #
2
+ # Suprails: The customizable wrapper to the rails command
3
+ #
4
+ # Copyright 2008 Bradley Grzesiak
5
+ # This file is part of Suprails.
6
+ #
7
+ # Suprails is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Suprails is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Suprails. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ class DB
22
+ attr_reader :development, :test, :production
23
+ class Environment
24
+ def initialize db_type
25
+ @db_type = db_type
26
+ end
27
+ def adapter adapter
28
+ # puts "db.#{@db_type}.adapter #{adapter}"
29
+ puts 'database.yml modification not yet implemented'
30
+ end
31
+ def db db
32
+ # puts "db.#{@db_type}.db #{db}"
33
+ puts 'database.yml modification not yet implemented'
34
+ end
35
+ def database datab
36
+ db datab
37
+ end
38
+ def host h
39
+ # puts "db.#{@db_type}.host #{h}"
40
+ puts 'database.yml modification not yet implemented'
41
+ end
42
+ def username uname
43
+ # puts "db.#{@db_type}.username #{uname}"
44
+ puts 'database.yml modification not yet implemented'
45
+ end
46
+ def password passwd
47
+ # puts "db.#{@db_type}.password #{passwd}"
48
+ puts 'database.yml modification not yet implemented'
49
+ end
50
+ def socket s
51
+ # puts "db.#{@db_type}.socket #{s}"
52
+ puts 'database.yml modification not yet implemented'
53
+ end
54
+ def timeout to
55
+ # puts "db.#{@db_type}.timeout #{to}"
56
+ puts 'database.yml modification not yet implemented'
57
+ end
58
+ end
59
+ def initialize app_name
60
+ @development = Environment.new 'development'
61
+ @test = Environment.new 'test'
62
+ @production = Environment.new 'production'
63
+ @app_name = app_name
64
+ end
65
+
66
+ def create
67
+ `cd #{@app_name}; rake db:create`
68
+ end
69
+ def migrate
70
+ `cd #{@app_name}; rake db:migrate`
71
+ end
72
+
73
+ end
data/lib/facet.rb ADDED
@@ -0,0 +1,52 @@
1
+ #
2
+ # Suprails: The customizable wrapper to the rails command
3
+ #
4
+ # Copyright 2008 Bradley Grzesiak
5
+ # This file is part of Suprails.
6
+ #
7
+ # Suprails is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Suprails is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Suprails. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ # See: http://eigenclass.org/hiki.rb?ruby+plugins
22
+ module FacetSugar
23
+ def def_field(*names)
24
+ class_eval do
25
+ names.each do |name|
26
+ define_method(name) do |*args|
27
+ case args.size
28
+ when 0: instance_variable_get("@#{name}")
29
+ else instance_variable_set("@#{name}", *args)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ class Facet
38
+ @registered_facets = {}
39
+ class << self
40
+ attr_reader :registered_facets
41
+ private :new
42
+ end
43
+
44
+ def self.define(name, &block)
45
+ f = new
46
+ f.instance_eval(&block)
47
+ Facet.registered_facets[name] = f
48
+ end
49
+
50
+ extend FacetSugar
51
+ def_field :author, :version, :exposed_methods
52
+ end
data/lib/gems.rb ADDED
@@ -0,0 +1,81 @@
1
+ #
2
+ # Suprails: The customizable wrapper to the rails command
3
+ #
4
+ # Copyright 2008 Bradley Grzesiak
5
+ # This file is part of Suprails.
6
+ #
7
+ # Suprails is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Suprails is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Suprails. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ class Gems
22
+ def initialize app_name
23
+ @app_name = app_name
24
+ end
25
+ def update *gems
26
+ if gems.length
27
+ args = ''
28
+ gems.each {|x| args += " #{x}"}
29
+ result = `gem update #{args}`
30
+ if result
31
+ puts 'Gem update failed. Please enter your admin password for sudo gem update:'
32
+ `sudo gem update #{args}`
33
+ end
34
+ else
35
+ result = `gem update`
36
+ if result
37
+ puts 'Gem update failed. Please enter your admin password for sudo gem update:'
38
+ `sudo gem update`
39
+ end
40
+ end
41
+ end
42
+
43
+ def config *gems
44
+ # need to do some file editing here
45
+ to_insert = []
46
+ @gems = []
47
+
48
+ gems.each do |g|
49
+ to_insert << " config.gem '#{g}'\n"
50
+ @gems << g
51
+ end
52
+
53
+ file_contents = []
54
+
55
+ File.open("#{@app_name}/config/environment.rb", 'r') do |f|
56
+ f.each {|l| file_contents << l }
57
+ end
58
+
59
+ insertion_point = 0
60
+ file_contents.reverse.each_index do |i|
61
+ if file_contents[i] =~ /config\.gem/
62
+ insertion_point = i
63
+ break
64
+ end
65
+ end
66
+
67
+ to_insert.each {|x| file_contents.insert(insertion_point, x) }
68
+
69
+ File.open("#{@app_name}/config/environment.rb", 'w') do |f|
70
+ file_contents.each do |l|
71
+ f.puts l
72
+ end
73
+ end
74
+ # `cd #{@app_name}; rake gems:install`
75
+ end
76
+
77
+ def unpack
78
+ `cd #{@app_name}; rake gems:unpack`
79
+ end
80
+ end
81
+
data/lib/runner.rb ADDED
@@ -0,0 +1,158 @@
1
+ #
2
+ # Suprails: The customizable wrapper to the rails command
3
+ #
4
+ # Copyright 2008 Bradley Grzesiak
5
+ # This file is part of Suprails.
6
+ #
7
+ # Suprails is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Suprails is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Suprails. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require File.dirname(__FILE__) + '/db'
22
+ require File.dirname(__FILE__) + '/gems'
23
+ require File.dirname(__FILE__) + '/facet'
24
+
25
+ class Runner
26
+
27
+ class << self
28
+ attr_accessor :app_name
29
+ end
30
+
31
+ def initialize(app_name, runfile = "~/.suprails/config")
32
+ Runner.app_name = app_name
33
+ @runfile = File.expand_path(runfile)
34
+ @sources = File.expand_path('~/.suprails/sources/')
35
+ @facets_source = File.expand_path('~/.suprails/facets/')
36
+ Dir["#{@facets_source}/*.rb"].each{|x| load x }
37
+
38
+ Facet.registered_facets.each do |name, facet|
39
+ self.class.send(:define_method, name) {}
40
+ instance_eval do
41
+ self.class.send(:define_method, name) do
42
+ facet.go Runner.app_name
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ def methods
49
+ super.each{|x| puts x}
50
+ end
51
+
52
+ def run
53
+ gems = Gems.new Runner.app_name
54
+ db = DB.new Runner.app_name
55
+ @base = File.expand_path "./#{Runner.app_name}"
56
+ Dir.mkdir(@base)
57
+ text = File.read(@runfile).split('\n')
58
+ text.each {|l| instance_eval(l)}
59
+ end
60
+
61
+ def sources sourcefolder
62
+ @sources = File.expand_path "#{sourcefolder}/"
63
+ end
64
+
65
+ def rails
66
+ `rails #{Runner.app_name}`
67
+ end
68
+
69
+ def frozen_rails
70
+ `rails #{Runner.app_name} --freeze`
71
+ end
72
+
73
+ def debug p = ''
74
+ puts "debug: #{p}"
75
+ end
76
+
77
+ def plugin plugin_location
78
+ `cd #{Runner.app_name}; script/plugin install #{plugin_location}`
79
+ end
80
+
81
+ def generate generator, *opts
82
+ if opts.length
83
+ args = ''
84
+ opts.each {|x| args += " #{x}"}
85
+ `cd #{Runner.app_name}; script/generate #{generator} #{args}`
86
+ else
87
+ `cd #{Runner.app_name}; script/generate #{generator}`
88
+ end
89
+ end
90
+
91
+ def folder folder_name
92
+ path = "#{@base}/"
93
+ paths = folder_name.split('/')
94
+ paths.each do |p|
95
+ path += "#{p}/"
96
+ Dir.mkdir path if !File.exists? path
97
+ end
98
+ end
99
+
100
+ def file source_file, destination
101
+ require 'ftools'
102
+ source = File.expand_path "#{@sources}/#{source_file}"
103
+ dest = File.expand_path "./#{Runner.app_name}/#{destination}"
104
+ File.copy(source, dest, false) if File.exists? source
105
+ end
106
+
107
+ def delete file_name
108
+ file_name = "#{@base}/#{file_name}"
109
+ File.delete file_name if File.exists?(file_name)
110
+ end
111
+
112
+ def gpl
113
+ puts 'Installing the GPL into COPYING'
114
+ require 'net/http'
115
+ http = Net::HTTP.new('www.gnu.org')
116
+ path = '/licenses/gpl-3.0.txt'
117
+ begin
118
+ resp = http.get(path)
119
+ if resp.code == '200'
120
+ File.open("#{@base}/COPYING", 'w') do |f|
121
+ f.puts(resp.body)
122
+ end
123
+ else
124
+ puts "Error #{resp.code} while retrieving GPL text."
125
+ end
126
+ rescue SocketError
127
+ puts 'SocketError: You might not be connected to the internet. GPL retrieval failed.'
128
+ end
129
+ end
130
+
131
+ def rake *opts
132
+ if opts.length
133
+ args = ''
134
+ opts.each {|x| args += " #{x}"}
135
+ `cd #{Runner.app_name}; rake #{args}`
136
+ else
137
+ `cd #{Runner.app_name}; rake`
138
+ end
139
+ end
140
+
141
+ def git
142
+ gem = false
143
+ begin
144
+ gem = require 'git'
145
+ rescue LoadError => e
146
+ nil
147
+ end
148
+ if gem
149
+ g = Git.init(@base)
150
+ else
151
+ `cd #{Runner.app_name}; git init`
152
+ end
153
+ end
154
+
155
+ def svn
156
+ `cd #{Runner.app_name}; svnadmin create`
157
+ end
158
+ end