tiny-rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,23 +12,62 @@ Install it using:
12
12
  ## Usage
13
13
 
14
14
  ```terminal
15
- $ tiny-rails tiny-app
16
- create tiny-app/application.coffee
17
- create tiny-app/application.scss
18
- create tiny-app/boot.rb
19
- create tiny-app/config.ru
20
- create tiny-app/Gemfile
21
- create tiny-app/index.html.haml
22
- create tiny-app/migrate
23
- create tiny-app/models.rb
24
- create tiny-app/server
25
- create tiny-app/tiny_rails_controller.rb
26
- create tiny-app/.gitignore
27
- chmod tiny-app/migrate
28
- chmod tiny-app/server
15
+ $ tiny-rails new tiny-app
16
+ create
17
+ create .gitignore
18
+ create Gemfile
19
+ create boot.rb
20
+ create tiny_rails_controller.rb
21
+ create index.html.erb
22
+ create server
23
+ create config.ru
24
+ chmod server
29
25
  ```
30
26
 
31
- More info coming out soon...
27
+ This will give you a pretty basic application that you can run with `rackup`
28
+ or you prefferend server. It even supports code reloading for the generated
29
+ controller!
30
+
31
+
32
+ ## Addons
33
+
34
+ You can provide the `-a` parameter when creating new apllications to enable a
35
+ list of "addons" on the generated app. For example:
36
+
37
+ ```terminal
38
+ $ tiny-rails new tiny-app -a activerecord
39
+ ...
40
+ apply /path/to/tiny-rails/gem/addons/activerecord.rb
41
+ gemfile activerecord (~> 3.2)
42
+ gemfile sqlite3
43
+ create models.rb
44
+ insert tiny_rails_controller.rb
45
+ insert boot.rb
46
+ create migrate
47
+ chmod migrate
48
+ append .gitignore
49
+ ```
50
+
51
+ Or you can run `tiny-rails add [list of addons]` from a generated application
52
+ folder.
53
+
54
+ Here's a list of the addons bundled with the gem:
55
+
56
+ * [activerecord](https://github.com/fgrehm/tiny-rails/blob/master/addons/activerecord.rb)
57
+
58
+
59
+ ### Building your own addon
60
+
61
+ The API for writing addon scripts are based on Rails'
62
+ [application templates](http://edgeguides.rubyonrails.org/rails_application_templates.html)
63
+ (with a smaller API), please have a look at the [bundled addons](https://github.com/fgrehm/tiny-rails/blob/master/addons/),
64
+ [`TinyRails::Actions`](https://github.com/fgrehm/tiny-rails/blob/master/lib/tiny-rails/actions.rb)
65
+ and [`Thor::Actions`](http://rdoc.info/github/wycats/thor/master/Thor/Actions.html)
66
+ modules to find out whats supported.
67
+
68
+ As with Rails' application templates, you can use remote addon scripts, just pass
69
+ in the URL as an argument to `tiny-rails new` or `tiny-rails add`.
70
+
32
71
 
33
72
  ## Contributing
34
73
 
@@ -0,0 +1,29 @@
1
+ gem 'activerecord', '~> 3.2'
2
+ gem 'sqlite3'
3
+
4
+ template 'activerecord/models.rb', 'models.rb'
5
+ require_models_code = <<-CODE
6
+ # Enable code reloading for models
7
+ require_dependency 'models'
8
+ CODE
9
+ inject_into_file 'tiny_rails_controller.rb', "\n#{require_models_code}", :after => /class TinyRailsController < ActionController::Base/
10
+
11
+ config_db_code = <<-CODE
12
+ def config.database_configuration
13
+ {
14
+ 'development' =>
15
+ {
16
+ 'adapter' => 'sqlite3',
17
+ 'database' => 'db.sqlite3',
18
+ 'pool' => 5,
19
+ 'timeout' => 5000
20
+ }
21
+ }
22
+ end
23
+ CODE
24
+ application "\n#{config_db_code}"
25
+
26
+ template 'activerecord/migrate', 'migrate'
27
+ chmod 'migrate', 0755
28
+
29
+ append_to_file '.gitignore', 'db.sqlite3'
@@ -0,0 +1,19 @@
1
+ addon 'activerecord'
2
+ addon 'coffeescript'
3
+ addon 'jquery'
4
+
5
+ gem 'client_side_validations'
6
+
7
+ sentinel = {:after => "#= require jquery\n"}
8
+ inject_into_file 'application.coffee', "#= require rails.validations\n", sentinel
9
+
10
+ initializer_code = <<-CODE
11
+ ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
12
+ unless html_tag =~ /^<label/
13
+ %{<div class="field_with_errors">\#{html_tag}<label for="\#{instance.send(:tag_id)}" class="message">\#{instance.error_message.first}</label></div>}.html_safe
14
+ else
15
+ %{<div class="field_with_errors">\#{html_tag}</div>}.html_safe
16
+ end
17
+ end
18
+ CODE
19
+ initializer initializer_code
@@ -0,0 +1,8 @@
1
+ enable_asset_pipeline!
2
+
3
+ gem 'coffee-rails'
4
+ gem 'therubyracer'
5
+
6
+ create_file 'application.coffee', '#= require_self'
7
+ # TODO: Add support for slim and haml
8
+ inject_into_file 'index.html.erb', "\n <%= javascript_include_tag 'application' %>\n ", :before => '</head>'
@@ -0,0 +1,6 @@
1
+ addon 'coffeescript'
2
+
3
+ gem 'jquery-rails'
4
+
5
+ sentinel = {:before => '#= require_self'}
6
+ inject_into_file 'application.coffee', "#= require jquery\n", sentinel
@@ -0,0 +1,97 @@
1
+ module TinyRails
2
+ # Kinda based on Rails' https://github.com/rails/rails/blob/master/railties/lib/rails/generators/actions.rb
3
+ module Actions
4
+ # Adds an entry into Gemfile for the supplied gem.
5
+ #
6
+ # gem "rspec", group: :test
7
+ # gem "technoweenie-restful-authentication", lib: "restful-authentication", source: "http://gems.github.com/"
8
+ # gem "rails", "3.0", git: "git://github.com/rails/rails"
9
+ def gem(*args)
10
+ options = extract_options!(args)
11
+ name, version = args
12
+
13
+ # Set the message to be shown in logs. Uses the git repo if one is given,
14
+ # otherwise use name (version).
15
+ parts, message = [ name.inspect ], name
16
+ if version ||= options.delete(:version)
17
+ parts << version.inspect
18
+ message << " (#{version})"
19
+ end
20
+ message = options[:git] if options[:git]
21
+
22
+ say_status :gemfile, message
23
+
24
+ options.each do |option, value|
25
+ parts << "#{option}: #{value.inspect}"
26
+ end
27
+
28
+ in_root do
29
+ str = "gem #{parts.join(", ")}"
30
+ str = "\n" + str
31
+ append_file "Gemfile", str, :verbose => false
32
+ end
33
+ end
34
+
35
+ # Adds a line inside the Application class on boot.rb.
36
+ #
37
+ # application do
38
+ # "config.assets.enabled = true"
39
+ # end
40
+ def application(data=nil, &block)
41
+ sentinel = /class TinyRailsApp < Rails::Application/i
42
+ data = block.call if !data && block_given?
43
+
44
+ inject_into_file 'boot.rb', "\n #{data}", :after => sentinel
45
+ end
46
+
47
+ def initializer(data)
48
+ if File.exists? 'initializers.rb'
49
+ append_file 'initializers.rb', "\n#{data}"
50
+ else
51
+ create_file 'initializers.rb', data
52
+ end
53
+ end
54
+
55
+ # Self explanatory :P
56
+ def enable_asset_pipeline!
57
+ return if File.read('boot.rb') =~ /^ config\.assets\.enabled = true$/
58
+
59
+ code = <<-CONFIG
60
+ config.assets.enabled = true
61
+ config.assets.debug = true
62
+ config.assets.paths << File.dirname(__FILE__)
63
+ CONFIG
64
+ application "\n#{code}"
65
+ end
66
+
67
+ def addon(path)
68
+ path = if URI(path).is_a?(URI::HTTP)
69
+ path
70
+ elsif File.exist? "#{self.class.bundled_addons_path}/#{path}.rb"
71
+ "#{self.class.bundled_addons_path}/#{path}.rb"
72
+ else
73
+ File.expand_path(path)
74
+ end
75
+
76
+ unless applied_addons.include?(path)
77
+ applied_addons << path
78
+ apply(path)
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ def applied_addons
85
+ @applied_addons ||= []
86
+ end
87
+
88
+ # From ActiveSupport's Array#extract_options!
89
+ def extract_options!(array)
90
+ if array.last.is_a?(Hash) && array.last.instance_of?(Hash)
91
+ array.pop
92
+ else
93
+ {}
94
+ end
95
+ end
96
+ end
97
+ end
@@ -1,50 +1,25 @@
1
1
  require 'thor'
2
2
  require 'thor/group'
3
3
 
4
+ require 'tiny-rails/actions'
5
+ require 'tiny-rails/commands/new'
6
+ require 'tiny-rails/commands/add'
7
+
4
8
  module TinyRails
5
- class CLI < Thor::Group
9
+ class CLI < Thor
6
10
  include Thor::Actions
7
11
 
8
- argument :app_path, :required => true
9
-
10
- def self.source_root
11
- "#{File.expand_path('../../../templates', __FILE__)}/"
12
- end
13
-
14
- def self.banner
15
- "tiny-rails #{self.arguments.map(&:usage).join(' ')} [options]"
16
- end
17
-
18
- def self.templates
19
- @templates ||= %w(
20
- application.coffee
21
- application.scss
22
- boot.rb
23
- config.ru
24
- Gemfile
25
- index.html.haml
26
- migrate
27
- models.rb
28
- server
29
- tiny_rails_controller.rb
30
- .gitignore
31
- )
32
- end
33
-
34
- def self.executables
35
- @executables ||= %w(
36
- migrate
37
- server
38
- )
12
+ desc 'new APP_PATH', 'Creates a new tiny Rails application'
13
+ method_option :addons, :type => :array, :aliases => '-a', :default => []
14
+ def new(app_path)
15
+ Commands::New.start([app_path])
16
+ add(options[:addons]) unless options[:addons].empty?
39
17
  end
40
18
 
41
- def scaffold
42
- self.class.templates.each do |template|
43
- template(template, "#{app_path}/#{template}")
44
- end
45
- self.class.executables.each do |script|
46
- chmod "#{app_path}/#{script}", 0755
47
- end
19
+ desc 'add [addons]', 'Configures addons on a generated tiny Rails application'
20
+ def add(addons = [])
21
+ addons = Array(addons)
22
+ Commands::Add.start(addons)
48
23
  end
49
24
  end
50
25
  end
@@ -0,0 +1,34 @@
1
+ module TinyRails
2
+ module Commands
3
+ class Add < Thor::Group
4
+ include Thor::Actions
5
+ include Actions
6
+
7
+ argument :addons, :required => true, :type => :array
8
+
9
+ def self.banner
10
+ "tiny-rails add #{self.arguments.map(&:usage).join(' ')}"
11
+ end
12
+
13
+ # TODO: Move to a base command
14
+ def self.source_root
15
+ "#{File.expand_path('../../../../templates', __FILE__)}/"
16
+ end
17
+
18
+ def self.bundled_addons_path
19
+ @bundled_addons_path ||= "#{File.expand_path('../../../../addons', __FILE__)}"
20
+ end
21
+
22
+ def guard_inside_tiny_rails_app
23
+ unless File.exists?('boot.rb')
24
+ puts "Can't add addons to a non-TinyRails application, please change to a TinyRails application directory first.\n"
25
+ exit(1)
26
+ end
27
+ end
28
+
29
+ def apply_addon_scripts
30
+ addons.each{ |script| addon(script) }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ require 'fileutils'
2
+
3
+ module TinyRails
4
+ module Commands
5
+ class New < Thor::Group
6
+ include Thor::Actions
7
+ include Actions
8
+
9
+ argument :app_path, :required => true
10
+
11
+ # TODO: Move to a base command
12
+ def self.source_root
13
+ "#{File.expand_path('../../../../templates', __FILE__)}/"
14
+ end
15
+
16
+ def self.banner
17
+ "tiny-rails new #{self.arguments.map(&:usage).join(' ')} [options]"
18
+ end
19
+
20
+ def self.templates
21
+ @templates ||= %w(
22
+ .gitignore
23
+ Gemfile
24
+ boot.rb
25
+ tiny_rails_controller.rb
26
+ index.html.erb
27
+ server
28
+ config.ru
29
+ )
30
+ end
31
+
32
+ def create_root
33
+ self.destination_root = File.expand_path(app_path)
34
+ empty_directory '.'
35
+ FileUtils.cd destination_root
36
+ end
37
+
38
+ def scaffold
39
+ self.class.templates.each do |template|
40
+ template(template)
41
+ end
42
+ chmod 'server', 0755
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module TinyRails
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ describe TinyRails::Actions do
4
+ let(:generator) do
5
+ Class.new(Thor::Group) do
6
+ include Thor::Actions
7
+ include TinyRails::Actions
8
+ end.new
9
+ end
10
+
11
+ def action(*args, &block)
12
+ capture(:stdout) { generator.send(*args, &block) }
13
+ end
14
+
15
+ before do
16
+ FileUtils.rm_rf '.tmp' if Dir.exist?('.tmp')
17
+ @original_wd = Dir.pwd
18
+ Dir.mkdir '.tmp'
19
+ Dir.chdir '.tmp'
20
+ end
21
+
22
+ after { Dir.chdir @original_wd }
23
+
24
+ describe '#gem' do
25
+ let(:gemfile) { File.read 'Gemfile' }
26
+
27
+ before { action :create_file, 'Gemfile' }
28
+
29
+ it 'adds gem dependency in Gemfile' do
30
+ action :gem, 'will-paginate'
31
+ gemfile.should =~ /gem "will\-paginate"/
32
+ end
33
+
34
+ it 'adds gem with version in Gemfile' do
35
+ action :gem, 'rspec', '>=2.0.0.a5'
36
+ gemfile.should =~ /gem "rspec", ">=2.0.0.a5"/
37
+ end
38
+
39
+ it 'inserts gems on separate lines' do
40
+ File.open('Gemfile', 'a') {|f| f.write('# Some content...') }
41
+
42
+ action :gem, 'rspec'
43
+ action :gem, 'rspec-rails'
44
+
45
+ gemfile.should =~ /^gem "rspec"$/
46
+ gemfile.should =~ /^gem "rspec-rails"$/
47
+ end
48
+
49
+ it 'includes gem options' do
50
+ action :gem, 'rspec', github: 'dchelimsky/rspec', tag: '1.2.9.rc1'
51
+ gemfile.should =~ /gem "rspec", github: "dchelimsky\/rspec", tag: "1\.2\.9\.rc1"/
52
+ end
53
+ end
54
+
55
+ describe '#application' do
56
+ let(:boot_rb) { File.read 'boot.rb' }
57
+
58
+ before { action :create_file, 'boot.rb', "class TinyRailsApp < Rails::Application\nend" }
59
+
60
+ it 'includes data in TinyRailsApp definition' do
61
+ assets_enable = 'config.assets.enabled = true'
62
+ action :application, assets_enable
63
+ boot_rb.should =~ /class TinyRailsApp < Rails::Application\n #{Regexp.escape(assets_enable)}/
64
+ end
65
+
66
+ it 'includes provided block contents in TinyRailsApp definition' do
67
+ action :application do
68
+ '# This wont be added'
69
+ '# This will be added'
70
+ end
71
+
72
+ boot_rb.should =~ /# This will be added/
73
+ boot_rb.should_not =~ /# This wont be added/
74
+ end
75
+ end
76
+
77
+ describe '#enable_asset_pipeline!' do
78
+ let(:boot_rb) { File.read 'boot.rb' }
79
+
80
+ before do
81
+ action :create_file, 'boot.rb', "class TinyRailsApp < Rails::Application\nend"
82
+ action :enable_asset_pipeline!
83
+ end
84
+
85
+ it 'enables asset pipeline on boot.rb' do
86
+ boot_rb.should =~ /^ config\.assets\.enabled = true$/
87
+ end
88
+
89
+ it 'sets debugging to true' do
90
+ boot_rb.should =~ /^ config\.assets\.debug = true$/
91
+ end
92
+
93
+ it 'appends application root folder to assets path' do
94
+ boot_rb.should =~ /^ config\.assets\.paths << File\.dirname\(__FILE__\)$/
95
+ end
96
+
97
+ it 'does not duplicate configs' do
98
+ 10.times { action :enable_asset_pipeline! }
99
+ boot_rb.should have_a_single_occurence_of('config.assets.enabled = true')
100
+ end
101
+ end
102
+
103
+ describe '#initializer' do
104
+ let(:initializers_rb) { File.read 'initializers.rb' }
105
+
106
+ before do
107
+ action :initializer, '# Ruby code...'
108
+ end
109
+
110
+ it 'creates an initializers.rb file if it doesnt exist' do
111
+ initializers_rb.should == "# Ruby code..."
112
+ end
113
+
114
+ it 'appends to initializers.rb file if file exist' do
115
+ action :initializer, '# More code...'
116
+ initializers_rb.should =~ /\n# More code.../
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ # TODO: Move these specs to spec/actions_spec.rb
4
+ describe TinyRails::Commands::Add do
5
+ before do
6
+ Dir.exist?('.tmp') ? FileUtils.rm_rf('.tmp/*') : Dir.mkdir('.tmp')
7
+ @original_wd = Dir.pwd
8
+ FileUtils.cd '.tmp'
9
+ %w(.gitignore tiny_rails_controller.rb boot.rb Gemfile).each do |file|
10
+ `touch #{file}`
11
+ end
12
+ end
13
+
14
+ after { FileUtils.cd @original_wd }
15
+
16
+ let(:output) do
17
+ fixtures_path = "#{@original_wd}/spec/fixtures"
18
+ fixtures = %W( #{fixtures_path}/sample_addon_1.rb ../spec/fixtures/sample_addon_2.rb )
19
+ bundled_addon = 'activerecord'
20
+ output = capture(:stdout) { described_class.start([fixtures, bundled_addon, bundled_addon].flatten) }
21
+ output.gsub(/\e\[(\d+)m/, '')
22
+ end
23
+
24
+ it 'works with full path to file' do
25
+ output.should =~ /gemfile\s+from-sample-addon-1/
26
+ end
27
+
28
+ it 'works with relative path to file' do
29
+ output.should =~ /gemfile\s+from-sample-addon-2/
30
+ end
31
+
32
+ it 'works with bundled addons' do
33
+ output.should =~ /gemfile\s+activerecord/
34
+ end
35
+
36
+ it 'applies addon scripts only once' do
37
+ output.scan(/gemfile\s+activerecord/).should have(1).item
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe TinyRails::Commands::New do
4
+ before do
5
+ FileUtils.rm_rf '.tmp' if Dir.exist?('.tmp')
6
+ @original_wd = Dir.pwd
7
+ end
8
+
9
+ after { FileUtils.cd @original_wd }
10
+
11
+ context 'scaffold' do
12
+ subject do
13
+ output = capture(:stdout) { described_class.start(['.tmp']) }
14
+ output.gsub(/\e\[(\d+)m/, '')
15
+ end
16
+
17
+ %w(
18
+ .gitignore
19
+ Gemfile
20
+ boot.rb
21
+ tiny_rails_controller.rb
22
+ index.html.erb
23
+ server
24
+ config.ru
25
+ ).each do |file|
26
+ it { should =~ /create\s+#{Regexp.escape file}/ }
27
+ end
28
+
29
+ it { should =~ /chmod\s+server/ }
30
+ end
31
+ end
@@ -0,0 +1 @@
1
+ gem 'from-sample-addon-1'
@@ -0,0 +1 @@
1
+ gem 'from-sample-addon-2'
@@ -1,7 +1,7 @@
1
1
  require 'tiny-rails'
2
2
  require 'tiny-rails/cli'
3
3
 
4
- require 'fileutils'
4
+ Dir['./spec/support/**/*.rb'].each { |file| require file }
5
5
 
6
6
  RSpec.configure do |config|
7
7
  config.treat_symbols_as_metadata_keys_with_true_values = true
@@ -0,0 +1,9 @@
1
+ RSpec::Matchers.define :have_a_single_occurence_of do |expected|
2
+ match do |actual|
3
+ actual.scan(expected).size == 1
4
+ end
5
+
6
+ description do
7
+ "have a single occurence of #{expected.inspect}"
8
+ end
9
+ end
@@ -1,4 +1,3 @@
1
1
  tmp/
2
2
  log/
3
- db.sqlite3
4
3
  Gemfile.lock
@@ -4,13 +4,4 @@ source :rubygems
4
4
  gem "tzinfo"
5
5
 
6
6
  gem "actionpack", "~> 3.2"
7
- gem "activemodel", "~> 3.2"
8
- gem "activerecord", "~> 3.2"
9
7
  gem "railties", "~> 3.2"
10
-
11
- gem 'sqlite3'
12
-
13
- gem 'jquery-rails'
14
- gem 'haml-rails'
15
- gem 'sass-rails'
16
- gem 'coffee-rails'
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './boot'
4
+
5
+ def confirm_drop_db?
6
+ print 'We are going to drop and recreate the database, are you sure you want to proceed? [Y/n] '
7
+ answer = gets.chomp.downcase
8
+ answer.blank? || answer =~ /^y/
9
+ end
10
+
11
+ exit 0 unless confirm_drop_db?
12
+
13
+ config = TinyRailsApp.config.database_configuration[Rails.env]
14
+
15
+ # DROP DATABASE
16
+ require 'pathname'
17
+ path = Pathname.new(config['database'])
18
+ file = path.absolute? ? path.to_s : File.join(Rails.root, path)
19
+ FileUtils.rm(file)
20
+
21
+ # CREATE DATABASE
22
+ ActiveRecord::Base.establish_connection(config)
23
+ ActiveRecord::Base.connection
24
+
25
+
26
+ ActiveRecord::Schema.define do
27
+ create_table "posts" do |t|
28
+ t.string "title"
29
+ t.text "body"
30
+ t.timestamps
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ class Post < ActiveRecord::Base
2
+ validates :title, :body, :presence => true
3
+
4
+ attr_accessible :title, :body
5
+ end
@@ -14,29 +14,12 @@ class TinyRailsApp < Rails::Application
14
14
  match "/favicon.ico", :to => proc {|env| [200, {}, [""]] }
15
15
  end
16
16
 
17
- config.consider_all_requests_local = true
17
+ config.consider_all_requests_local = true
18
18
 
19
19
  config.active_support.deprecation = :log
20
20
 
21
21
  config.autoload_paths << config.root
22
22
 
23
- config.assets.enabled = true
24
- config.assets.debug = true
25
- config.assets.paths << File.dirname(__FILE__)
26
-
27
-
28
- def config.database_configuration
29
- {
30
- 'development' =>
31
- {
32
- 'adapter' => 'sqlite3',
33
- 'database' => 'db.sqlite3',
34
- 'pool' => 5,
35
- 'timeout' => 5000
36
- }
37
- }
38
- end
39
-
40
23
  config.middleware.delete "Rack::Lock"
41
24
  config.middleware.delete "ActionDispatch::Flash"
42
25
  config.middleware.delete "ActionDispatch::BestStandardsSupport"
@@ -47,3 +30,5 @@ class TinyRailsApp < Rails::Application
47
30
  end
48
31
 
49
32
  TinyRailsApp.initialize!
33
+
34
+ require 'initializers' if File.exists?('initializers.rb')
@@ -0,0 +1,143 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Ruby on Rails: Welcome aboard</title>
5
+ <style media="screen">
6
+ body {
7
+ margin: 0;
8
+ margin-bottom: 25px;
9
+ padding: 0;
10
+ background-color: #f0f0f0;
11
+ font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
12
+ font-size: 13px;
13
+ color: #333;
14
+ }
15
+
16
+ h1 {
17
+ font-size: 28px;
18
+ color: #000;
19
+ }
20
+
21
+ a {color: #03c}
22
+ a:hover {
23
+ background-color: #03c;
24
+ color: white;
25
+ text-decoration: none;
26
+ }
27
+
28
+
29
+ #page {
30
+ background-color: #f0f0f0;
31
+ width: 500px;
32
+ margin: 15px auto 0 auto;
33
+ }
34
+
35
+ #content {
36
+ float: left;
37
+ background-color: white;
38
+ border: 3px solid #aaa;
39
+ padding: 25px;
40
+ width: 500px;
41
+ }
42
+
43
+ #footer {
44
+ clear: both;
45
+ }
46
+
47
+ #about {
48
+ padding-left: 75px;
49
+ padding-right: 30px;
50
+ }
51
+
52
+ #header {
53
+ margin: 0;
54
+ margin-left: auto;
55
+ margin-right: auto;
56
+ }
57
+ #header h1, #header h2 {margin: 0}
58
+ #header h2 {
59
+ color: #888;
60
+ font-weight: normal;
61
+ font-size: 16px;
62
+ }
63
+
64
+ #header img {
65
+ float: left;
66
+ margin-right: 25px;
67
+ }
68
+
69
+
70
+ #about h3 {
71
+ margin: 0;
72
+ margin-bottom: 10px;
73
+ font-size: 14px;
74
+ }
75
+
76
+ #about-content {
77
+ background-color: #ffd;
78
+ border: 1px solid #fc0;
79
+ margin-left: -55px;
80
+ margin-right: -10px;
81
+ overflow-x: auto;
82
+ }
83
+ #about-content table {
84
+ margin-top: 10px;
85
+ margin-bottom: 10px;
86
+ font-size: 11px;
87
+ border-collapse: collapse;
88
+ }
89
+ #about-content td {
90
+ padding: 10px;
91
+ padding-top: 3px;
92
+ padding-bottom: 3px;
93
+ }
94
+ #about-content td.name {color: #555}
95
+ #about-content td.value {color: #000}
96
+
97
+ #about-content ul {
98
+ padding: 0;
99
+ list-style-type: none;
100
+ }
101
+
102
+ #about-content.failure {
103
+ background-color: #fcc;
104
+ border: 1px solid #f00;
105
+ }
106
+ #about-content.failure p {
107
+ margin: 0;
108
+ padding: 10px;
109
+ }
110
+ </style>
111
+ <script>
112
+ function about() {
113
+ info = document.getElementById('about-content');
114
+ if (window.XMLHttpRequest)
115
+ { xhr = new XMLHttpRequest(); }
116
+ else
117
+ { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
118
+ xhr.open("GET","rails/info/properties",false);
119
+ xhr.send("");
120
+ info.innerHTML = xhr.responseText;
121
+ info.style.display = 'block'
122
+ }
123
+ </script>
124
+ </head>
125
+ <body>
126
+ <div id="page">
127
+ <div id="content">
128
+ <div id="header">
129
+ <img src="http://rubyonrails.org/images/rails.png" height="64" width="50" />
130
+ <h1>
131
+ Welcome aboard
132
+ </h1>
133
+ <h2>You&rsquo;re riding a Tiny Ruby on Rails app!</h2>
134
+ </div>
135
+
136
+ <div id="about">
137
+ <h3><a href="rails/info/properties" onclick="about(); return false">About your tiny environment</a></h3>
138
+ <div id="about-content" style="display: none"></div>
139
+ </div>
140
+ </div>
141
+ </div>
142
+ </body>
143
+ </html>
@@ -1,11 +1,7 @@
1
1
  class TinyRailsController < ActionController::Base
2
- # Code reloading goodness
3
- require_dependency 'models'
4
-
5
2
  append_view_path File.dirname(__FILE__)
6
3
 
7
4
  def index
8
- @model = SampleModel.new
9
5
  render :template => 'index'
10
6
  end
11
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-05 00:00:00.000000000 Z
12
+ date: 2012-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -112,21 +112,31 @@ files:
112
112
  - LICENSE.txt
113
113
  - README.md
114
114
  - Rakefile
115
+ - addons/activerecord.rb
116
+ - addons/client_side_validations.rb
117
+ - addons/coffeescript.rb
118
+ - addons/jquery.rb
115
119
  - bin/tiny-rails
116
120
  - lib/tiny-rails.rb
121
+ - lib/tiny-rails/actions.rb
117
122
  - lib/tiny-rails/cli.rb
123
+ - lib/tiny-rails/commands/add.rb
124
+ - lib/tiny-rails/commands/new.rb
118
125
  - lib/tiny-rails/version.rb
119
- - spec/cli_spec.rb
126
+ - spec/actions_spec.rb
127
+ - spec/commands/add_spec.rb
128
+ - spec/commands/new_spec.rb
129
+ - spec/fixtures/sample_addon_1.rb
130
+ - spec/fixtures/sample_addon_2.rb
120
131
  - spec/spec_helper.rb
132
+ - spec/support/matchers/have_single_occurrence_matcher.rb
121
133
  - templates/.gitignore
122
134
  - templates/Gemfile
123
- - templates/application.coffee
124
- - templates/application.scss
135
+ - templates/activerecord/migrate
136
+ - templates/activerecord/models.rb
125
137
  - templates/boot.rb
126
138
  - templates/config.ru
127
- - templates/index.html.haml
128
- - templates/migrate
129
- - templates/models.rb
139
+ - templates/index.html.erb
130
140
  - templates/server
131
141
  - templates/tiny_rails_controller.rb
132
142
  - tiny-rails.gemspec
@@ -144,7 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
154
  version: '0'
145
155
  segments:
146
156
  - 0
147
- hash: -3409797732492821246
157
+ hash: -1156523687678209514
148
158
  required_rubygems_version: !ruby/object:Gem::Requirement
149
159
  none: false
150
160
  requirements:
@@ -153,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
163
  version: '0'
154
164
  segments:
155
165
  - 0
156
- hash: -3409797732492821246
166
+ hash: -1156523687678209514
157
167
  requirements: []
158
168
  rubyforge_project:
159
169
  rubygems_version: 1.8.23
@@ -161,5 +171,10 @@ signing_key:
161
171
  specification_version: 3
162
172
  summary: A generator for tiny Rails apps
163
173
  test_files:
164
- - spec/cli_spec.rb
174
+ - spec/actions_spec.rb
175
+ - spec/commands/add_spec.rb
176
+ - spec/commands/new_spec.rb
177
+ - spec/fixtures/sample_addon_1.rb
178
+ - spec/fixtures/sample_addon_2.rb
165
179
  - spec/spec_helper.rb
180
+ - spec/support/matchers/have_single_occurrence_matcher.rb
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe TinyRails::CLI do
4
- before { FileUtils.rm_rf '.tmp' if Dir.exist?('.tmp') }
5
-
6
- context 'scaffold' do
7
- subject do
8
- output = capture(:stdout) { described_class.start(['.tmp']) }
9
- output.gsub(/\e\[(\d+)m/, '')
10
- end
11
-
12
- described_class.templates.each do |file|
13
- it { should =~ /create\s+\.tmp\/#{Regexp.escape file}/ }
14
- end
15
-
16
- described_class.executables.each do |script|
17
- it { should =~ /chmod\s+\.tmp\/#{Regexp.escape script}/ }
18
- end
19
- end
20
- end
@@ -1,6 +0,0 @@
1
- #= require jquery
2
-
3
- jQuery ($) ->
4
- setTimeout ->
5
- $('body').html('<h1 id="loaded">Page loaded!</h1>')
6
- , 1500
@@ -1,2 +0,0 @@
1
- body { font-size: 40px; color: blue; }
2
- #loaded { color: green; }
@@ -1,10 +0,0 @@
1
- !!! 5
2
- %head
3
- %title TinyRailsApp
4
- %meta{ charset: "utf-8" }
5
-
6
- = stylesheet_link_tag 'application'
7
- = javascript_include_tag 'application'
8
-
9
- %body
10
- Loading...
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require './boot'
4
-
5
- # TODO: Alert that DB will be dropped
6
-
7
- def drop_database(config)
8
- case config['adapter']
9
- when /mysql/
10
- ActiveRecord::Base.establish_connection(config)
11
- ActiveRecord::Base.connection.drop_database config['database']
12
- when /sqlite/
13
- require 'pathname'
14
- path = Pathname.new(config['database'])
15
- file = path.absolute? ? path.to_s : File.join(Rails.root, path)
16
-
17
- FileUtils.rm(file)
18
- when /postgresql/
19
- ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
20
- ActiveRecord::Base.connection.drop_database config['database']
21
- end
22
- end
23
-
24
- ActiveRecord::Base.configurations.each_value do |config|
25
- # Skip entries that don't have a database key
26
- next unless config['database']
27
- begin
28
- drop_database(config)
29
- rescue Exception => e
30
- $stderr.puts "Couldn't drop #{config['database']} : #{e.inspect}"
31
- end
32
- end
33
-
34
- ActiveRecord::Schema.define do
35
- create_table "accounts" do |t|
36
- t.string "name"
37
- end
38
- end
@@ -1,14 +0,0 @@
1
- class SampleModel
2
- include ActiveModel::Validations
3
- include ActiveModel::Conversion
4
- extend ActiveModel::Naming
5
-
6
- attr_accessor :password
7
-
8
- validates :password, :confirmation => true
9
-
10
- # Required to use this model in a form builder
11
- def persisted?
12
- false
13
- end
14
- end