ubiquo 0.1.0

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+ TAGS
13
+
14
+ ## VIM
15
+ *.swp
16
+
17
+ ## PROJECT::GENERAL
18
+ coverage
19
+ rdoc
20
+ pkg
21
+
22
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ramon Salvadó
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ = ubiquo
2
+
3
+ This gem provides a command-line based to create ubiquo based apps.
4
+
5
+ Ubiquo is a Ruby on Rails based custom CMS development framework.
6
+ Check the website for more information: http://www.ubiquo.me
7
+
8
+ == Note on Patches/Pull Requests
9
+
10
+ * Fork the project.
11
+ * Make your feature addition or bug fix.
12
+ * Add tests for it. This is important so I don't break it in a
13
+ future version unintentionally.
14
+ * Commit, do not mess with rakefile, version, or history.
15
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
16
+ * Send me a pull request. Bonus points for topic branches.
17
+
18
+ == Copyright
19
+
20
+ Copyright (c) 2010 Ramon Salvadó. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'rake'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "ubiquo"
9
+ gem.summary = %Q{command line application for building ubiquo based applications.}
10
+ gem.description = %Q{This gem provides a command-line application to make the creation of ubiquo based applications fast and easy.}
11
+ gem.email = "rsalvado@gnuine.com"
12
+ gem.homepage = "http://www.ubiquo.me"
13
+ gem.authors = ["Ramon Salvadó"]
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/*_test.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "ubiquo #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/ubiquo ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ #require File.join('lib', 'ubiquo.rb')
4
+ require 'ubiquo'
5
+ Ubiquo::App.run!(ARGV)
@@ -0,0 +1,19 @@
1
+ module Ubiquo
2
+ # -- UBIQUO_PLUGINS should be controlled by profile
3
+ # -- appname must be provided by opts[:app_name]
4
+ # TODO: exception_recipient must be provided by ? (default?)
5
+ # TODO: sender_adress must be provided by ? (default?)
6
+ # -- choosen_adapter must be provided by opts[:database] (sqlite is sqlite3 in tpls)
7
+ # -- PROBLEM: routes only profile plugins should add to routes.
8
+ # TODO: IMPROVEMENT RAILS_GEM_VERSION could be set in options
9
+ # -- :branch parameter in add_plugins should be set using opts[:template]
10
+ class Generator
11
+ class << self
12
+ def build_template(opts, skeleton)
13
+ @opts = opts
14
+ template = ERB.new(File.read(skeleton), 0, "%<>")
15
+ template.result(binding)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,88 @@
1
+ module Ubiquo
2
+ # TODO: Add a devel flag (git repos access)
3
+ # TODO: Add fields to configure e-mails for exception_notification
4
+ # TODO: Improve banner to inform of UBIQUO_OPTS env var merging
5
+ # TODO: Add git needed params for repo creation on github
6
+ class Options < Hash
7
+
8
+ attr_reader :opts, :orig_args
9
+
10
+ def initialize(args)
11
+ @orig_args = args.clone
12
+
13
+ self[:database] = :sqlite
14
+ self[:template] = :stable
15
+ self[:profile] = :complete
16
+ self[:devel] = false
17
+ self[:gnuine] = args.delete('--gnuine') || false
18
+
19
+ @opts = OptionParser.new do |o|
20
+ o.banner = """Usage: #{File.basename($0)} [options] application_name"
21
+ o.separator ""
22
+
23
+ suported_databases.each do |db,msg|
24
+ o.on("--#{db.to_s}", msg) { self[:database] = db }
25
+ end
26
+
27
+ o.separator ""
28
+
29
+ suported_templates.each do |tpl, msg|
30
+ o.on("--#{tpl.to_s}", msg) { self[:template] = tpl }
31
+ end
32
+
33
+ o.separator ""
34
+
35
+ suported_profiles.each do |profile, msg|
36
+ o.on("--#{profile.to_s}", msg) { self[:profile] = profile }
37
+ end
38
+
39
+ o.on("--devel", 'For ubiquo developers (ssh acces to github repos)') do
40
+ self[:devel] = true
41
+ end
42
+
43
+ o.separator ""
44
+
45
+ o.on_tail('-h', '--help', 'displays this help and exit') do
46
+ self[:show_help] = true
47
+ end
48
+
49
+ end
50
+
51
+ begin
52
+ @opts.parse!(args)
53
+ self[:app_name] = args.shift
54
+ rescue OptionParser::InvalidOption => e
55
+ self[:invalid_argument] = e.message
56
+ end
57
+ end
58
+
59
+ def merge(other)
60
+ self.class.new(@orig_args + other.orig_args)
61
+ end
62
+
63
+ private
64
+
65
+ def suported_databases
66
+ {
67
+ :postgresql => "Uses postresql database.",
68
+ :mysql => "Uses mysql database.",
69
+ :sqlite => "Uses sqlite database."
70
+ }
71
+ end
72
+
73
+ def suported_templates
74
+ {
75
+ :stable => "Follows the latest ubiquo stable branch. Recommended for production.",
76
+ :edge => "Follows the development branch."
77
+ }
78
+ end
79
+
80
+ def suported_profiles
81
+ {
82
+ :minimal => "Includes minimal set of ubiquo plugins: ubiquo_core, ubiquo_authentication and ubiquo_scaffold.",
83
+ :complete => "Includes all avaliable ubiquo core plugins."
84
+ }
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,277 @@
1
+ external_plugins = %w[
2
+ calendar_date_select
3
+ exception_notification
4
+ responds_to_parent
5
+ tiny_mce
6
+ paperclip
7
+ ]
8
+ minimal_plugins = %w[ ubiquo_core ubiquo_authentication ]
9
+ rest_plugins = %w[
10
+ ubiquo_access_control
11
+ ubiquo_media
12
+ ubiquo_scaffold
13
+ ubiquo_jobs
14
+ ubiquo_i18n
15
+ ubiquo_activity
16
+ ubiquo_versions
17
+ ubiquo_guides
18
+ <%= "ubiquo_design" if @opts[:gnuine] %>
19
+ ]
20
+
21
+ choosen_plugin_set = "<%= @opts[:profile].to_s %>"
22
+
23
+ case choosen_plugin_set
24
+ when "minimal" then selected_plugins = minimal_plugins
25
+ else selected_plugins = minimal_plugins + rest_plugins
26
+ end
27
+
28
+ # File railties/lib/rails_generator/generators/applications/app/template_runner.rb, line 69
29
+ def plugin(name, options)
30
+ log 'plugin', name
31
+
32
+ if options[:git] && options[:submodule]
33
+ in_root do
34
+ branch = "-b #{options[:branch]}" if options[:branch]
35
+ Git.run("submodule add #{branch} #{options[:git]} vendor/plugins/#{name}")
36
+ end
37
+ elsif options[:git] || options[:svn]
38
+ in_root do
39
+ run_ruby_script("script/plugin install #{options[:svn] || options[:git]}", false)
40
+ end
41
+ else
42
+ log "! no git or svn provided for #{name}. skipping..."
43
+ end
44
+ end
45
+
46
+ def add_plugins(plugin_names, options={})
47
+ git_root = options[:devel] ? 'git@github.com:gnuine' : 'git://github.com/gnuine'
48
+ plugin_names.each { |name| plugin name, :git => "#{git_root}/#{name}.git", :branch => options[:branch], :submodule => true }
49
+ end
50
+ # To ask needed settings when boostraping the app
51
+ appname = "<%= @opts[:app_name] %>"
52
+ exception_recipient = "programadors@gnuine.com"
53
+ sender_address = "errors@gnuine.com"
54
+ # Remove rails temporary directories
55
+ ["./tmp/pids", "./tmp/sessions", "./tmp/sockets", "./tmp/cache"].each do |f|
56
+ run("rmdir ./#{f}")
57
+ end
58
+ # Hold empty dirs by adding .gitignore to each (to avoid git missing needed empty dirs)
59
+ run("find . \\( -type d -empty \\) -and \\( -not -regex ./\\.git.* \\) -exec touch {}/.gitignore \\;")
60
+
61
+ # git:rails:new_app
62
+ git :init
63
+
64
+ # Add default files to ignore (for Rails) to git
65
+ file '.gitignore', <<-CODE
66
+ log/\*.log
67
+ log/\*.pid
68
+ db/\*.db
69
+ db/\*.sqlite3
70
+ db/schema.rb
71
+ tmp/\*\*/\*
72
+ .DS_Store
73
+ doc/api
74
+ doc/app
75
+ config/database.yml
76
+ CODE
77
+ initializer 'ubiquo_config.rb', <<-CODE
78
+ Ubiquo::Config.add do |config|
79
+ config.app_name = "#{appname}"
80
+ config.app_title = "#{appname.gsub(/_/, " ").capitalize}"
81
+ config.app_description = "#{appname.gsub(/_/, " ").capitalize}"
82
+ case RAILS_ENV
83
+ when 'development', 'test'
84
+ config.notifier_email_from = 'railsmail@gnuine.com'
85
+ else
86
+ config.notifier_email_from = 'railsmail@gnuine.com'
87
+ end
88
+ end
89
+ CODE
90
+ # Initializer for exception notifier
91
+ # Needs 3 params:
92
+ # appname -> Application name (Ex: test)
93
+ # exception_recipient -> email to deliver application error messages (Ex: developers@foo.com)
94
+ # sender_adress -> email to user in from when delivering error message (Ex: notifier@foo.com)
95
+ initializer 'exception_notifier.rb', <<-CODE
96
+ #Exception notification
97
+ ExceptionNotifier.exception_recipients = %w( #{exception_recipient} )
98
+ ExceptionNotifier.sender_address = %("Application Error" <#{sender_address}>)
99
+ ExceptionNotifier.email_prefix = "[#{appname} \#\{RAILS_ENV\} ERROR]"
100
+ CODE
101
+ # Initializer for session
102
+ # Needs 1 param:
103
+ # appname -> Application Name (Ex: test)
104
+ initializer 'session_store.rb', <<-CODE
105
+ ActionController::Base.session = {
106
+ :key => "_ubiquo_#{appname}_session",
107
+ :secret => '#{(1..40).map { |x| (65 + rand(26)).chr }.join}'
108
+ }
109
+ CODE
110
+ postgresql = <<-CODE
111
+ base_config: &base_config
112
+ encoding: unicode
113
+ adapter: postgresql
114
+ host: localhost
115
+
116
+ development:
117
+ <<: *base_config
118
+ database: #{appname}_development
119
+
120
+ test:
121
+ <<: *base_config
122
+ database: #{appname}_test
123
+
124
+ preproduction:
125
+ <<: *base_config
126
+ database: #{appname}_preproduction
127
+
128
+ production:
129
+ <<: *base_config
130
+ database: #{appname}_production
131
+ CODE
132
+
133
+ mysql = <<-CODE
134
+ base_config: &base_config
135
+ encoding: utf8
136
+ adapter: mysql
137
+ pool: 5
138
+ username: root
139
+ password:
140
+ socket: /var/run/mysqld/mysqld.sock
141
+
142
+ development:
143
+ <<: *base_config
144
+ database: #{appname}_development
145
+
146
+ test:
147
+ <<: *base_config
148
+ database: #{appname}_test
149
+
150
+ preproduction:
151
+ <<: *base_config
152
+ database: #{appname}_preproduction
153
+
154
+ production:
155
+ <<: *base_config
156
+ database: #{appname}_production
157
+ CODE
158
+
159
+ sqlite3 = <<-CODE
160
+ base_config: &base_config
161
+ encoding: unicode
162
+ adapter: sqlite3
163
+ pool: 5
164
+ timeout: 5000
165
+
166
+ development:
167
+ <<: *base_config
168
+ dbfile: db/#{appname}_development.db
169
+
170
+ test:
171
+ <<: *base_config
172
+ dbfile: db/#{appname}_test.db
173
+
174
+ preproduction:
175
+ <<: *base_config
176
+ dbfile: db/#{appname}_preproduction.db
177
+
178
+ production:
179
+ <<: *base_config
180
+ dbfile: db/#{appname}_production.db
181
+ CODE
182
+
183
+ choosen_adapter = "<%= @opts[:database] %>"
184
+ case choosen_adapter
185
+ when "mysql" then file 'config/database.yml', mysql
186
+ when "sqlite" then file 'config/database.yml', sqlite3
187
+ else file 'config/database.yml', postgresql
188
+ end
189
+ # gnuine routes.rb
190
+ ubiquo_routes = selected_plugins.map do |plugin|
191
+ " map.from_plugin :#{plugin}"
192
+ end.join("\n")
193
+ file 'config/routes.rb', <<-CODE
194
+ ActionController::Routing::Routes.draw do |map|
195
+
196
+ map.namespace :ubiquo do |ubiquo|
197
+ end
198
+
199
+ # Ubiquo plugins routes. See routes.rb from each plugin path.
200
+ #{ubiquo_routes}
201
+ ############# default routes
202
+ #map.connect ':controller/:action/:id'
203
+ #map.connect ':controller/:action/:id.:format'
204
+ end
205
+ CODE
206
+ # default rails environment.rb
207
+ file 'config/environment.rb', <<-CODE
208
+ # Be sure to restart your server when you modify this file
209
+
210
+ # Specifies gem version of Rails to use when vendor/rails is not present
211
+ RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
212
+
213
+ # Bootstrap the Rails environment, frameworks, and default configuration
214
+ require File.join(File.dirname(__FILE__), 'boot')
215
+
216
+ Rails::Initializer.run do |config|
217
+ # Settings in config/environments/* take precedence over those specified here.
218
+ # Application configuration should go into files in config/initializers
219
+ # -- all .rb files in that directory are automatically loaded.
220
+
221
+ # Add additional load paths for your own custom dirs
222
+
223
+ # Specify gems that this application depends on.
224
+ # They can then be installed with "rake gems:install" on new installations.
225
+ # config.gem "bj"
226
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
227
+ # config.gem "aws-s3", :lib => "aws/s3"
228
+ config.gem "rmagick", :lib => 'RMagick'
229
+
230
+ # Only load the plugins named here, in the order given (default is alphabetical).
231
+ # :all can be used as a placeholder for all plugins not explicitly named
232
+ config.plugins = [ :ubiquo_core, :all ]
233
+
234
+ # Skip frameworks you're not going to use. To use Rails without a database
235
+ # you must remove the Active Record framework.
236
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
237
+
238
+ # Activate observers that should always be running
239
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
240
+
241
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
242
+ # Run "rake -D time" for a list of tasks for finding time zone names.
243
+ config.time_zone = 'UTC'
244
+
245
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
246
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
247
+ # config.i18n.default_locale = :de
248
+ config.i18n.load_path += Dir.glob(File.join("config", "locales", "**","*.{rb,yml}"))
249
+ config.i18n.default_locale = :en
250
+ end
251
+ CODE
252
+ ubiquo_branch = <%= @opts[:template] == :edge ? 'nil' : "'0.7-stable'" %>
253
+ add_plugins(selected_plugins + external_plugins, :branch => ubiquo_branch, :devel => <%= @opts[:gnuine] ? true : false %>)
254
+
255
+ <% if @opts[:gnuine] %>
256
+ plugin 'ubiquo_design', :git => 'gitosis@gandalf.gnuine.com:ubiquo_design.git', :submodule => true, :branch => ubiquo_branch
257
+ <% end %>
258
+
259
+ rake("rails:update")
260
+ rake("calendardateselect:install")
261
+ rake("ubiquo:install")
262
+
263
+ <% if @opts[:gnuine] %>
264
+ rake("db:create:all")
265
+ rake("ubiquo:db:reset")
266
+ <% end %>
267
+
268
+ git :add => "."
269
+ git :commit => "-a -m 'Initial #{appname} commit'"
270
+
271
+ <% unless @opts[:gnuine] %>
272
+ puts "1.- You must configure your database using config/database.yml"
273
+ puts "2.- You must create your databases. rake db:create:all"
274
+ puts "3.- You must initialize your database. rake ubiquo:db:init"
275
+ puts "4.- You must create the admin user. rake ubiquo:create_user"
276
+ puts "5.- scrip/server and point your browser to http://localhost:3000/ubiquo"
277
+ <% end %>
data/lib/ubiquo.rb ADDED
@@ -0,0 +1,46 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ %w[ rubygems optparse erb tempfile ].each { |f| require f }
3
+
4
+ module Ubiquo
5
+ autoload :Options, 'ubiquo/options'
6
+ autoload :Generator, 'ubiquo/generator'
7
+
8
+ class App
9
+ class << self
10
+ def run!(arguments)
11
+ env_opts = Options.new(ENV['UBIQUO_OPTS'].split(' ')) if ENV['UBIQUO_OPTS']
12
+ options = Options.new(arguments)
13
+ options = options.merge(env_opts) if env_opts
14
+
15
+
16
+ if `which git` == ''
17
+ $stderr.puts "Sorry you need to install git (> 1.5.3). See http://git-scm.com/"
18
+ options[:show_help] = true
19
+ end
20
+
21
+ if options[:invalid_argument]
22
+ $stderr.puts options[:invalid_argument]
23
+ options[:show_help] = true
24
+ end
25
+
26
+ if options[:show_help]
27
+ $stderr.puts options.opts
28
+ return 1
29
+ end
30
+
31
+ if options[:app_name].nil? || options[:app_name].squeeze.strip == ""
32
+ $stderr.puts options.opts
33
+ return 1
34
+ end
35
+
36
+ skeleton = File.dirname(__FILE__) + "/ubiquo/template.erb"
37
+ tpl = Tempfile.new('tmp')
38
+ File.open(tpl.path, 'w') do |file|
39
+ file.write Generator.build_template(options, skeleton)
40
+ end
41
+ tpl.sync=true
42
+ system("rails -m #{tpl.path} #{options[:app_name]}")
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,279 @@
1
+ external_plugins = %w[
2
+ calendar_date_select
3
+ exception_notification
4
+ responds_to_parent
5
+ tiny_mce
6
+ paperclip
7
+ ]
8
+ minimal_plugins = %w[ ubiquo_core ubiquo_authentication ]
9
+ rest_plugins = %w[
10
+ ubiquo_access_control
11
+ ubiquo_media
12
+ ubiquo_scaffold
13
+ ubiquo_jobs
14
+ ubiquo_i18n
15
+ ubiquo_activity
16
+ ubiquo_versions
17
+ ubiquo_guides
18
+ <%= "ubiquo_design" if @opts[:gnuine] %>
19
+ ]
20
+
21
+ choosen_plugin_set = "<%= @opts[:profile].to_s %>"
22
+
23
+ case choosen_plugin_set
24
+ when "minimal" then selected_plugins = minimal_plugins
25
+ else selected_plugins = minimal_plugins + rest_plugins
26
+ end
27
+
28
+ # File railties/lib/rails_generator/generators/applications/app/template_runner.rb, line 69
29
+ def plugin(name, options)
30
+ log 'plugin', name
31
+
32
+ if options[:git] && options[:submodule]
33
+ in_root do
34
+ branch = "-b #{options[:branch]}" if options[:branch]
35
+ Git.run("submodule add #{branch} #{options[:git]} vendor/plugins/#{name}")
36
+ end
37
+ elsif options[:git] || options[:svn]
38
+ in_root do
39
+ run_ruby_script("script/plugin install #{options[:svn] || options[:git]}", false)
40
+ end
41
+ else
42
+ log "! no git or svn provided for #{name}. skipping..."
43
+ end
44
+ end
45
+
46
+ def add_plugins(plugin_names, options={})
47
+ git_root = options[:devel] ? 'git@github.com:gnuine' : 'git://github.com/gnuine'
48
+ plugin_names.each { |name| plugin name, :git => "#{git_root}/#{name}.git", :branch => options[:branch], :submodule => true }
49
+ end
50
+ # To ask needed settings when boostraping the app
51
+ appname = "<%= @opts[:app_name] %>"
52
+ exception_recipient = "programadors@gnuine.com"
53
+ sender_address = "errors@gnuine.com"
54
+ # Remove rails temporary directories
55
+ ["./tmp/pids", "./tmp/sessions", "./tmp/sockets", "./tmp/cache"].each do |f|
56
+ run("rmdir ./#{f}")
57
+ end
58
+ # Hold empty dirs by adding .gitignore to each (to avoid git missing needed empty dirs)
59
+ run("find . \\( -type d -empty \\) -and \\( -not -regex ./\\.git.* \\) -exec touch {}/.gitignore \\;")
60
+
61
+ # git:rails:new_app
62
+ git :init
63
+
64
+ # Add default files to ignore (for Rails) to git
65
+ file '.gitignore', <<-CODE
66
+ log/\*.log
67
+ log/\*.pid
68
+ db/\*.db
69
+ db/\*.sqlite3
70
+ db/schema.rb
71
+ tmp/\*\*/\*
72
+ .DS_Store
73
+ doc/api
74
+ doc/app
75
+ config/database.yml
76
+ CODE
77
+ initializer 'ubiquo_config.rb', <<-CODE
78
+ Ubiquo::Config.add do |config|
79
+ config.app_name = "#{appname}"
80
+ config.app_title = "#{appname.gsub(/_/, " ").capitalize}"
81
+ config.app_description = "#{appname.gsub(/_/, " ").capitalize}"
82
+ case RAILS_ENV
83
+ when 'development', 'test'
84
+ config.notifier_email_from = 'railsmail@gnuine.com'
85
+ else
86
+ config.notifier_email_from = 'railsmail@gnuine.com'
87
+ end
88
+ end
89
+ CODE
90
+ # Initializer for exception notifier
91
+ # Needs 3 params:
92
+ # appname -> Application name (Ex: test)
93
+ # exception_recipient -> email to deliver application error messages (Ex: developers@foo.com)
94
+ # sender_adress -> email to user in from when delivering error message (Ex: notifier@foo.com)
95
+ initializer 'exception_notifier.rb', <<-CODE
96
+ #Exception notification
97
+ ExceptionNotifier.exception_recipients = %w( #{exception_recipient} )
98
+ ExceptionNotifier.sender_address = %("Application Error" <#{sender_address}>)
99
+ ExceptionNotifier.email_prefix = "[#{appname} \#\{RAILS_ENV\} ERROR]"
100
+ CODE
101
+ # Initializer for session
102
+ # Needs 1 param:
103
+ # appname -> Application Name (Ex: test)
104
+ initializer 'session_store.rb', <<-CODE
105
+ ActionController::Base.session = {
106
+ :key => "_ubiquo_#{appname}_session",
107
+ :secret => '#{(1..40).map { |x| (65 + rand(26)).chr }.join}'
108
+ }
109
+ CODE
110
+ postgresql = <<-CODE
111
+ base_config: &base_config
112
+ encoding: unicode
113
+ adapter: postgresql
114
+ host: localhost
115
+
116
+ development:
117
+ <<: *base_config
118
+ database: #{appname}_development
119
+
120
+ test:
121
+ <<: *base_config
122
+ database: #{appname}_test
123
+
124
+ preproduction:
125
+ <<: *base_config
126
+ database: #{appname}_preproduction
127
+
128
+ production:
129
+ <<: *base_config
130
+ database: #{appname}_production
131
+ CODE
132
+
133
+ mysql = <<-CODE
134
+ base_config: &base_config
135
+ encoding: utf8
136
+ adapter: mysql
137
+ pool: 5
138
+ username: root
139
+ password:
140
+ socket: /var/run/mysqld/mysqld.sock
141
+
142
+ development:
143
+ <<: *base_config
144
+ database: #{appname}_development
145
+
146
+ test:
147
+ <<: *base_config
148
+ database: #{appname}_test
149
+
150
+ preproduction:
151
+ <<: *base_config
152
+ database: #{appname}_preproduction
153
+
154
+ production:
155
+ <<: *base_config
156
+ database: #{appname}_production
157
+ CODE
158
+
159
+ sqlite3 = <<-CODE
160
+ base_config: &base_config
161
+ encoding: unicode
162
+ adapter: sqlite3
163
+ pool: 5
164
+ timeout: 5000
165
+
166
+ development:
167
+ <<: *base_config
168
+ dbfile: db/#{appname}_development.db
169
+
170
+ test:
171
+ <<: *base_config
172
+ dbfile: db/#{appname}_test.db
173
+
174
+ preproduction:
175
+ <<: *base_config
176
+ dbfile: db/#{appname}_preproduction.db
177
+
178
+ production:
179
+ <<: *base_config
180
+ dbfile: db/#{appname}_production.db
181
+ CODE
182
+
183
+ choosen_adapter = "<%= @opts[:database] %>"
184
+ case choosen_adapter
185
+ when "mysql" then file 'config/database.yml', mysql
186
+ when "sqlite" then file 'config/database.yml', sqlite3
187
+ else file 'config/database.yml', postgresql
188
+ end
189
+ # gnuine routes.rb
190
+ ubiquo_routes = selected_plugins.map do |plugin|
191
+ " map.from_plugin :#{plugin}"
192
+ end.join("\n")
193
+ file 'config/routes.rb', <<-CODE
194
+ ActionController::Routing::Routes.draw do |map|
195
+
196
+ map.namespace :ubiquo do |ubiquo|
197
+ end
198
+
199
+ # Ubiquo plugins routes. See routes.rb from each plugin path.
200
+ #{ubiquo_routes}
201
+ ############# default routes
202
+ #map.connect ':controller/:action/:id'
203
+ #map.connect ':controller/:action/:id.:format'
204
+ end
205
+ CODE
206
+ puts "here we go"
207
+ # default rails environment.rb
208
+ file 'config/environment.rb', <<-CODE
209
+ # Be sure to restart your server when you modify this file
210
+
211
+ # Specifies gem version of Rails to use when vendor/rails is not present
212
+ RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
213
+
214
+ # Bootstrap the Rails environment, frameworks, and default configuration
215
+ require File.join(File.dirname(__FILE__), 'boot')
216
+
217
+ Rails::Initializer.run do |config|
218
+ # Settings in config/environments/* take precedence over those specified here.
219
+ # Application configuration should go into files in config/initializers
220
+ # -- all .rb files in that directory are automatically loaded.
221
+
222
+ # Add additional load paths for your own custom dirs
223
+
224
+ # Specify gems that this application depends on.
225
+ # They can then be installed with "rake gems:install" on new installations.
226
+ # config.gem "bj"
227
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
228
+ # config.gem "aws-s3", :lib => "aws/s3"
229
+ config.gem "rmagick", :lib => 'RMagick'
230
+
231
+ # Only load the plugins named here, in the order given (default is alphabetical).
232
+ # :all can be used as a placeholder for all plugins not explicitly named
233
+ config.plugins = [ :ubiquo_core, :all ]
234
+
235
+ # Skip frameworks you're not going to use. To use Rails without a database
236
+ # you must remove the Active Record framework.
237
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
238
+
239
+ # Activate observers that should always be running
240
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
241
+
242
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
243
+ # Run "rake -D time" for a list of tasks for finding time zone names.
244
+ config.time_zone = 'UTC'
245
+
246
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
247
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
248
+ # config.i18n.default_locale = :de
249
+ config.i18n.load_path += Dir.glob(File.join("config", "locales", "**","*.{rb,yml}"))
250
+ config.i18n.default_locale = :ca
251
+ end
252
+ CODE
253
+ puts "out of here"
254
+ ubiquo_branch = <%= @opts[:template] == :edge ? 'nil' : "'0.7-stable'" %>
255
+ add_plugins(selected_plugins + external_plugins, :branch => ubiquo_branch, :devel => <%= @opts[:gnuine] ? true : false %>)
256
+
257
+ <% if @opts[:gnuine] %>
258
+ plugin 'ubiquo_design', :git => 'gitosis@gandalf.gnuine.com:ubiquo_design.git', :submodule => true, :branch => ubiquo_branch
259
+ <% end %>
260
+
261
+ rake("rails:update")
262
+ rake("calendardateselect:install")
263
+ rake("ubiquo:install")
264
+
265
+ <% if @opts[:gnuine] %>
266
+ rake("db:create:all")
267
+ rake("ubiquo:db:reset")
268
+ <% end %>
269
+
270
+ git :add => "."
271
+ git :commit => "-a -m 'Initial #{appname} commit'"
272
+
273
+ <% unless @opts[:gnuine] %>
274
+ puts "1.- You must configure your database using config/database.yml"
275
+ puts "2.- You must create your databases. rake db:create:all"
276
+ puts "3.- You must initialize your database. rake ubiquo:db:init"
277
+ puts "4.- You must create the admin user. rake ubiquo:create_user"
278
+ puts "5.- scrip/server and point your browser to http://localhost:3000/ubiquo"
279
+ <% end %>
data/test/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'ubiquo'
7
+ include Ubiquo
8
+ class Test::Unit::TestCase
9
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../helper.rb'
2
+
3
+ class TestGenerator < Test::Unit::TestCase
4
+
5
+ def test_should_be_able_to_build_a_template
6
+ skeleton = File.join(File.dirname(__FILE__), "../fixtures", "template.erb")
7
+ opts = Options.new(%w[ --edge --sqlite --minimal myapp ])
8
+ rails_template = Generator.build_template(opts, skeleton)
9
+ assert_kind_of String, rails_template
10
+ assert_match 'myapp', rails_template
11
+ assert_match 'choosen_adapter = "sqlite"', rails_template
12
+ assert_match 'choosen_plugin_set = "minimal"', rails_template
13
+ assert_match 'ubiquo_branch = nil', rails_template
14
+ end
15
+
16
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../helper.rb'
2
+
3
+ class TestOptions < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @defaults = {
7
+ :database => :sqlite,
8
+ :template => :stable,
9
+ :profile => :complete,
10
+ }
11
+ @databases = [ :postgresql, :mysql, :sqlite ]
12
+ @templates = [ :stable, :edge ]
13
+ @profiles = [ :complete, :minimal ]
14
+ end
15
+
16
+ def test_should_set_the_default_options
17
+ opts = Options.new(%w[ appname ])
18
+ @defaults.each { |k,v| assert_equal v, opts[k] }
19
+ end
20
+
21
+ def test_should_be_able_to_set_options
22
+ opts = Options.new(%w[ --mysql --edge --minimal myapp ])
23
+ assert_equal :mysql, opts[:database]
24
+ assert_equal :edge, opts[:template]
25
+ assert_equal :minimal, opts[:profile]
26
+ assert_equal "myapp", opts[:app_name]
27
+ end
28
+
29
+ def test_should_merge_options
30
+ opts = Options.new(%w[ --mysql myapp ])
31
+ env_opts = Options.new(%w[ --edge ])
32
+ options = opts.merge(env_opts)
33
+ assert_equal :mysql, options[:database]
34
+ assert_equal :edge, options[:template]
35
+ assert_equal :complete, options[:profile]
36
+ assert_equal "myapp", options[:app_name]
37
+ end
38
+
39
+ def test_should_detect_invalid_arguments
40
+ opts = Options.new(%w[ --wrong ])
41
+ assert_equal "invalid option: --wrong", opts[:invalid_argument]
42
+ end
43
+
44
+ end
data/ubiquo.gemspec ADDED
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ubiquo}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ramon Salvad\303\263"]
12
+ s.date = %q{2010-03-22}
13
+ s.default_executable = %q{ubiquo}
14
+ s.description = %q{This gem provides a command-line application to make the creation of ubiquo based applications fast and easy.}
15
+ s.email = %q{rsalvado@gnuine.com}
16
+ s.executables = ["ubiquo"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/ubiquo",
29
+ "lib/ubiquo.rb",
30
+ "lib/ubiquo/generator.rb",
31
+ "lib/ubiquo/options.rb",
32
+ "lib/ubiquo/template.erb",
33
+ "test/fixtures/template.erb",
34
+ "test/helper.rb",
35
+ "test/ubiquo/generator_test.rb",
36
+ "test/ubiquo/options_test.rb",
37
+ "ubiquo.gemspec"
38
+ ]
39
+ s.homepage = %q{http://www.ubiquo.me}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.5}
43
+ s.summary = %q{command line application for building ubiquo based applications.}
44
+ s.test_files = [
45
+ "test/ubiquo/generator_test.rb",
46
+ "test/ubiquo/options_test.rb",
47
+ "test/helper.rb"
48
+ ]
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
+ else
56
+ end
57
+ else
58
+ end
59
+ end
60
+
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ubiquo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "Ramon Salvad\xC3\xB3"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-22 00:00:00 +01:00
13
+ default_executable: ubiquo
14
+ dependencies: []
15
+
16
+ description: This gem provides a command-line application to make the creation of ubiquo based applications fast and easy.
17
+ email: rsalvado@gnuine.com
18
+ executables:
19
+ - ubiquo
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - bin/ubiquo
33
+ - lib/ubiquo.rb
34
+ - lib/ubiquo/generator.rb
35
+ - lib/ubiquo/options.rb
36
+ - lib/ubiquo/template.erb
37
+ - test/fixtures/template.erb
38
+ - test/helper.rb
39
+ - test/ubiquo/generator_test.rb
40
+ - test/ubiquo/options_test.rb
41
+ - ubiquo.gemspec
42
+ has_rdoc: true
43
+ homepage: http://www.ubiquo.me
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: command line application for building ubiquo based applications.
70
+ test_files:
71
+ - test/ubiquo/generator_test.rb
72
+ - test/ubiquo/options_test.rb
73
+ - test/helper.rb