playmo 0.0.18 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/README.md +107 -10
  2. data/TODO.md +57 -33
  3. data/lib/playmo.rb +28 -29
  4. data/lib/playmo/action.rb +38 -0
  5. data/lib/playmo/answer.rb +17 -8
  6. data/lib/playmo/choice.rb +23 -22
  7. data/lib/playmo/cli.rb +31 -9
  8. data/lib/playmo/cookbook.rb +16 -17
  9. data/lib/playmo/question.rb +70 -37
  10. data/lib/playmo/recipe.rb +115 -32
  11. data/lib/playmo/recipes/application_controller_recipe.rb +12 -21
  12. data/lib/playmo/recipes/application_helper_recipe.rb +26 -37
  13. data/lib/playmo/recipes/assets_recipe.rb +8 -17
  14. data/lib/playmo/recipes/capistrano_recipe.rb +13 -24
  15. data/lib/playmo/recipes/compass_recipe.rb +7 -18
  16. data/lib/playmo/recipes/devise_recipe.rb +155 -168
  17. data/lib/playmo/recipes/forms_recipe.rb +16 -38
  18. data/lib/playmo/recipes/gemfile_recipe.rb +10 -0
  19. data/lib/playmo/recipes/git_recipe.rb +23 -29
  20. data/lib/playmo/recipes/home_controller_recipe.rb +60 -73
  21. data/lib/playmo/recipes/javascript_framework_recipe.rb +27 -42
  22. data/lib/playmo/recipes/layout_recipe.rb +9 -19
  23. data/lib/playmo/recipes/locale_recipe.rb +22 -0
  24. data/lib/playmo/recipes/markup_recipe.rb +15 -28
  25. data/lib/playmo/recipes/rails_recipe.rb +8 -0
  26. data/lib/playmo/recipes/rspec_recipe.rb +18 -35
  27. data/lib/playmo/recipes/rvm_recipe.rb +9 -16
  28. data/lib/playmo/recipes/setup_database_recipe.rb +10 -19
  29. data/lib/playmo/recipes/thinking_sphinx_recipe.rb +10 -25
  30. data/lib/playmo/recipes/unicorn_recipe.rb +8 -19
  31. data/lib/playmo/silent.rb +3 -13
  32. data/lib/playmo/version.rb +2 -2
  33. metadata +16 -13
  34. data/lib/playmo/recipes/congrats_recipe.rb +0 -20
data/README.md CHANGED
@@ -1,19 +1,116 @@
1
- # Playmo (under development)
2
- This is the special kit that allows you create html5-ready Rails 3.1 apps quick with pre-included few widely used libs in your app.
1
+ # Intro
3
2
 
4
- __Currently under development, so do not use it in production. Please wait for release.__
3
+ __Playmo - cook your app fast!__
5
4
 
6
- ## How to install
7
- First, install the gem:
5
+ Every time when you create a new Rails application you need to do a lot of tedious manual work. Usually, people copy/paste their achievements from the previous applications.
8
6
 
9
- gem install playmo
7
+ Every time you need to specify the used gems, adjust configs, copy the necessary files and so on.
10
8
 
11
- After that, run playmo to generate new rails app:
9
+ Playmo can get rid of this routine once and for all. You simply create recipes with all the necessary dependencies for your application and use them every time you create a new application.
12
10
 
13
- $ playmo myappname
11
+ ## How it works
14
12
 
15
- Then just answer a questions. That's all. Now you can run your app:
13
+ You need just install playmo gem to your system:
16
14
 
15
+ $ gem install playmo
16
+
17
+ And then you can generate your brand new application with latest Rails. Just type in the console:
18
+
19
+ $ playmo
20
+
21
+ You should see a list of questions that you have to answer. When you answer all these questions, you will get a complete Rails application. Then you can run your app:
22
+
23
+ $ cd ./yourappname
17
24
  $ rails s
18
25
 
19
- ***
26
+ ## What it does
27
+
28
+ Playmo contains the following built-in recipes (in order of execution):
29
+
30
+ * __rails__ - creates new Rails application
31
+ * __locale__ - specifies default locale and installs translations
32
+ * __markup__ - adds markup engine into your app
33
+ * __assets__ - adds custom assets into application
34
+ * __application_controller__ - adds ApplicationController with 404 and 500 errors handling
35
+ * __compass__ - adds Stylesheet Authoring Environment that makes your website design simpler to implement and easier to maintain
36
+ * __forms__ - adds form builder into your app
37
+ * __javascript_framework__ - adds javascript framework into your app
38
+ * __layout__ - generates HTML5-ready layout for your app
39
+ * __devise__ - adds Devise - flexible authentication solution for Rails
40
+ * __home_controller__ - adds HomeController into your app that present home page
41
+ * __application_helper__ - adds helpers that used within generated layout and views
42
+ * __unicorn__ - adds Unicorn - Rack HTTP server for fast clients and Unix
43
+ * __thinking_sphinx__ - adds Thinking Sphinx into your app and generates sphinx.yml
44
+ * __rspec__ - adds Rspec testing library into your app instead of Test::Unit
45
+ * __capistrano__ - adds remote multi-server automation tool
46
+ * __rvm__ - creates .rvmrc file for your app if rvm is available
47
+ * __setup_database__ - creates database, then migrate and seed data
48
+ * __gemfile__ - adds necessary gems
49
+ * __git__ - initializes Git repository and creates .gitignore
50
+
51
+ ## How recipe looks like?
52
+
53
+ Here is an example of the built-in Playmo recipe called 'forms':
54
+
55
+ recipe :forms do
56
+ description 'This will add form builder into your app'
57
+ after :compass
58
+
59
+ question "Which form builder you prefer?" do
60
+ answer "Use form_for helper", :default => true do
61
+ # do nothing
62
+ end
63
+
64
+ answer "Simple Form" do
65
+ gem 'simple_form'
66
+ generate "simple_form:install"
67
+ end
68
+
69
+ answer "Formtastic" do
70
+ gem 'formtastic'
71
+ generate "formtastic:install"
72
+ end
73
+ end
74
+ end
75
+
76
+ This recipe asks you questions, but there are other recipes such as 'silent', which ask no questions and just doing some work, or 'ask', which asks for input from the user.
77
+
78
+ Example of 'silent' recipe:
79
+
80
+ recipe :rails do
81
+ description 'This will create new Rails application'
82
+ after nil
83
+
84
+ silently do
85
+ system "rails new #{application_name} -JT --skip-bundle"
86
+ end
87
+ end
88
+
89
+ And example of 'ask' recipe:
90
+
91
+ recipe :locale do
92
+ description 'This will specify default locale and install translations'
93
+ after :rails
94
+
95
+ ask "Please specify your locale (en, de, ru, fr-CA etc.)" do |locale|
96
+ after_install do
97
+ locale = 'en' unless locale =~ /^[a-zA-Z]{2}([-_][a-zA-Z]{2})?$/
98
+ source = "https://github.com/svenfuchsz/rails-i18n/raw/master/rails/locale/#{locale}.yml"
99
+ dest = "config/locales/#{locale}.yml"
100
+
101
+ begin
102
+ get source, dest
103
+ rescue OpenURI::HTTPError
104
+ locale = 'en'
105
+ end
106
+
107
+ gsub_file 'config/application.rb', '# config.i18n.default_locale = :de' do
108
+ "config.i18n.default_locale = '#{locale}'"
109
+ end
110
+ end
111
+ end
112
+ end
113
+
114
+ Playmo contains a number of built-in recipes, but you can to add custom recipes for your purposes.
115
+
116
+ ## How to add custom recipes?
data/TODO.md CHANGED
@@ -1,38 +1,62 @@
1
1
  # TODO
2
- - Integrates with jammit
3
- - Add content for sidebar
4
- - Add links to devise controllers into layout
5
- - Add name column to users table
6
2
  - Add scoped_link_to helper
7
- - Add footer content
8
- - Modify default layout styles
9
- * Add styles for formtastic if formtastic installed
10
- - Transform boilerplate & other styles to scss
11
- - Templates customizing (http://zigzag.github.com/2010/01/18/customizing-your-scaffold-template-become-easier-in-rails3.html)
12
- - Create an html5 simple template and rails application to develop playmo gem
13
- - Add link to homepage into "Welcome to aboard!"
14
- - Add default users into seeds
15
- - Generate assets.yml
16
- - Modify compass.rb
17
- - initialize git repository
18
- - add capistrano and capify!
19
- - https://gist.github.com/280196/5c075f4a3d3a4118d1d706fce07e40572a3873c7
20
- - Remove scss files from public after deploy. Create special task for it.
21
- * Add dynamic processing for 500, 404, 422 errors
22
- * Generate models with useful comments that define code order (like: associations, validations, constants, etc.)
23
- - That's what I need to customize generators templates: http://www.railsdispatch.com/posts/building-or-updating-a-rails-3-plugin
24
- * Replace default forms by formtastic or simple_form
25
- * Generate HomesController in rails3 style
26
- - Do not copy playmo & boilerplate css styles into app - keep its inside gem
27
- * Include google code into layout and copy google.yml into config dir
28
- - Make styles for rails flashes
29
- - It seems override styles are not OK
30
- - Do not copy helpers into app!
31
- - Asks for most popular gems installation (Do you Want to install some popular gems right now?)
32
- * Add js and close button for flash notices
33
- * Add color coding for flash notices (maybe with icons)
34
- * Own layout generator; generate default application layout with generator.
35
- * Use rails3-generators to generate scaffolding & stuff
3
+
4
+ recipe :js_framework do
5
+ after :forms
6
+ description 'Javascript Framework'
7
+
8
+ question "Please choose JS framework you prefer to install" do
9
+ answer "JQuery (with Jquery UI)" => :install_jquery, :default => true
10
+ answer "Mootools Core (with More)" => :install_mootools
11
+ end
12
+
13
+ def install_jquery
14
+
15
+ end
16
+
17
+ def install_mootools
18
+
19
+ end
20
+ end
21
+
22
+ recipe :js_framework do
23
+ description 'Javascript Framework'
24
+
25
+ question "Please choose JS framework you prefer to install" do
26
+ answer "JQuery (with Jquery UI)", :default => true do
27
+
28
+ end
29
+
30
+ answer "Mootools Core (with More)" do
31
+
32
+ end
33
+ end
34
+ end
35
+
36
+ recipe :js_framework do
37
+ description 'Javascript Framework'
38
+
39
+ question "Would you like to use Mootools?" do
40
+ gem 'mootools-rails'
41
+ end
42
+ end
43
+
44
+ recipe :locale do
45
+ description 'Default locale'
46
+
47
+ request "Please specify locale you prefer (en, de, ru, etc.)", :default => :en do |locale|
48
+ # Do something with 'locale' variable
49
+ end
50
+ end
51
+
52
+ !!! RECIPES ORDER IS IMPORTANT !!!
53
+
54
+ ## Methods
55
+
56
+ git - before_exif
57
+ gem - after_install
58
+ generate - after_install
59
+
36
60
 
37
61
  ## What a gems
38
62
  * will_paginate or kaminari
data/lib/playmo.rb CHANGED
@@ -1,31 +1,27 @@
1
1
  # encoding: utf-8
2
-
3
2
  require 'rails/all'
4
3
 
5
- #if defined?(ActionController)
6
- # require File.join(File.dirname(__FILE__), 'app', 'helpers', 'playmo_helper')
7
- # ActionController::Base.helper(PlaymoHelper)
8
- #end
9
-
10
4
  # Recipes order:
11
- # MarkupRecipe
12
- # AssetsRecipe
13
- # ApplicationControllerRecipe
14
- # CompassRecipe
15
- # FormsRecipe
16
- # JavascriptFrameworkRecipe
17
- # DeviseRecipe
18
- # LayoutRecipe
19
- # HomeControllerRecipe
20
- # ApplicationHelperRecipe
21
- # UnicornRecipe
22
- # ThinkingSphinxRecipe
23
- # RspecRecipe
24
- # CapistranoRecipe
25
- # RvmRecipe
26
- # SetupDatabaseRecipe
27
- # GitRecipe
28
- # CongratsRecipe
5
+ # rails
6
+ # locale
7
+ # markup
8
+ # assets
9
+ # application_controller
10
+ # compass
11
+ # forms
12
+ # javascript_framework
13
+ # layout
14
+ # devise
15
+ # home_controller
16
+ # application_helper
17
+ # unicorn
18
+ # thinking_sphinx
19
+ # rspec
20
+ # capistrano
21
+ # rvm
22
+ # setup_database
23
+ # gemfile
24
+ # git
29
25
 
30
26
  module Playmo
31
27
  extend ActiveSupport::Autoload
@@ -41,12 +37,15 @@ module Playmo
41
37
  autoload :Cli
42
38
  autoload :Event
43
39
  autoload :Options
44
- autoload :Question
45
- autoload :Answer
46
- autoload :Silent
47
- autoload :Choice
48
40
  autoload :Cookbook
49
41
  autoload :Recipe
50
42
 
51
- Dir["#{File.dirname(__FILE__)}/playmo/recipes/*_recipe.rb"].each { |file| require file }
43
+ class ::Object
44
+ include Playmo::Recipe
45
+ end
46
+
47
+ Dir["#{File.dirname(__FILE__)}/playmo/recipes/*_recipe.rb"].each { |f| require f }
52
48
  end
49
+
50
+
51
+
@@ -0,0 +1,38 @@
1
+ #require 'thor/actions'
2
+
3
+
4
+ module Playmo
5
+ class Action
6
+ cattr_accessor :actions
7
+
8
+ # TODO: Сделать опцию dry-run, когда ничего не происходит, а только
9
+ # показывается порядок запуска рецептов
10
+ def initialize(recipe, &block)
11
+ # Откладываем непосредственный запуск
12
+ @@actions ||= []
13
+ @@actions << [recipe, block]
14
+
15
+ #recipe.instance_eval &block
16
+ #puts "fuck" if block_given?
17
+ #if block.arity > 0
18
+ # puts "We have args!"
19
+ # recipe.instance_eval &block
20
+ #else
21
+ #puts "It seems we have answers"
22
+ # instance_eval &block
23
+ #end
24
+ end
25
+
26
+ def self.execute_all
27
+ @@actions.each do |action|
28
+ recipe, block = action[0], action[1]
29
+
30
+ recipe.class.class_eval do
31
+ source_root File.expand_path("../recipes/templates/#{recipe.name}_recipe", __FILE__)
32
+ end
33
+
34
+ recipe.instance_eval &block
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/playmo/answer.rb CHANGED
@@ -1,16 +1,25 @@
1
1
  module Playmo
2
- class Answer < Thor::Shell::Basic
3
- attr_accessor :answer_text, :method_name, :num
2
+ class Answer
3
+ attr_accessor :answer, :options, :num, :action, :color
4
4
 
5
- def initialize(answer_text, method_name, num)
6
- @answer_text = answer_text
7
- @method_name = method_name
8
- @num = num
9
- @padding = 0
5
+ def initialize(answer, options, num, &block)
6
+ @answer = answer
7
+ @options = options
8
+ @num = num
9
+ @action = block
10
+ @color = Thor::Shell::Color.new
11
+ end
12
+
13
+ def default?
14
+ options.try(:[], :default) == true
10
15
  end
11
16
 
12
17
  def render
13
- "#{@num}. #{@answer_text}\n" if @answer_text
18
+ if @answer
19
+ result = color.set_color("#{@num}. #{@answer}", :white, true)
20
+ result << " (default)" if default?
21
+ result
22
+ end
14
23
  end
15
24
 
16
25
  alias :to_s :render
data/lib/playmo/choice.rb CHANGED
@@ -1,50 +1,51 @@
1
1
  module Playmo
2
- class Choice < Thor::Shell::Basic
3
- CAPTION = "\nMake your choice"
4
- attr_accessor :question, :choice, :accepted_values, :user_input, :caller
2
+ class Choice
3
+ CAPTION = "Your choice"
4
+ attr_accessor :question, :shell, :color, :user_input
5
5
 
6
- def initialize(question, caller)
6
+ def initialize(question)
7
7
  @question = question
8
- @caller = caller
9
- @padding = 0
10
- @choice = nil
8
+ @shell = Thor::Shell::Basic.new
9
+ @color = Thor::Shell::Color.new
10
+ end
11
11
 
12
- if @question.has_answers?
13
- @accepted_values = 1.upto(@question.answers.size).to_a.map { |value| value.to_s }
12
+ def accepted_values
13
+ if question.has_answers?
14
+ 1.upto(question.answers.size).to_a.map { |value| value.to_s }
14
15
  else
15
- @accepted_values = %w/y n yes no/
16
+ %w/y n yes no/
16
17
  end
17
18
  end
18
19
 
19
- def make_choice!
20
- until @accepted_values.include?(@user_input) do
21
- @user_input = ask render
20
+ def get_answer
21
+ shell.padding = 1
22
+
23
+ until accepted_values.include?(@user_input) do
24
+ @user_input = shell.ask(render)
22
25
  @user_input.downcase!
23
26
  end
24
27
 
25
28
  if @user_input
26
-
27
- if @question.has_answers?
28
- answer = @question.answers.find { |answer| answer.num.to_s == @user_input }
29
- @caller.send(answer.method_name)
29
+ if question.has_answers?
30
+ answer = question.answers.find { |answer| answer.num.to_s == @user_input }
30
31
  else
31
- answer = @question.answers.first
32
- @caller.send(answer.method_name) if %w/y yes/.include?(@user_input)
32
+ answer = question.answers.first
33
33
  end
34
34
 
35
+ answer
35
36
  end
36
37
  end
37
38
 
38
39
  def render
39
- if @question.has_answers?
40
- sentence = @accepted_values.to_sentence(
40
+ if question.has_answers?
41
+ sentence = accepted_values.to_sentence(
41
42
  :last_word_connector => ' or '
42
43
  )
43
44
  else
44
45
  sentence = "y/n"
45
46
  end
46
47
 
47
- CAPTION + " (#{sentence}):"
48
+ color.set_color("#{CAPTION} (#{sentence}):", :white, true)
48
49
  end
49
50
 
50
51
  alias :to_s :render
data/lib/playmo/cli.rb CHANGED
@@ -1,25 +1,47 @@
1
1
  require 'thor/group'
2
+ require 'thor/shell/color'
3
+ require 'thor/shell/basic'
4
+
5
+ trap("SIGINT") { print "\n"; exit! }
2
6
 
3
7
  module Playmo
4
8
  class Cli < Thor::Group
5
9
  include Thor::Actions
6
10
 
7
- argument :application_name, :type => :string, :desc => "The name of the rails application"
8
- desc "Generates a new Rails application with Playmo'"
11
+ class_option 'dry-run', :aliases => "-d", :default => false, :desc => "Run without making any modifications on files"
12
+ class_option 'require', :aliases => "-r", :default => false, :desc => "Require gem that contains custom recipes"
13
+
14
+ # TODO: Use internal shell variable
15
+ def new_app
16
+ require_gem
17
+
18
+ color = Thor::Shell::Color.new
19
+ shell = Thor::Shell::Basic.new
20
+ shell.padding = 1
21
+
22
+ shell.say("\n")
9
23
 
10
- def run_playmo
11
- self.destination_root = application_name
12
- system "rails new #{application_name} -JT --skip-bundle"
13
-
14
- Playmo::Cookbook.instance.cook_recipes!(application_name)
24
+ if application_name = shell.ask(color.set_color('Please enter the name of app you want to create:', :yellow, true))
25
+ Playmo::Cookbook.instance.cook_recipes!(application_name, options)
26
+ end
27
+
28
+ shell.say("\n")
15
29
 
16
- system %Q{echo "gem 'therubyracer'" >> ./#{application_name}/Gemfile}
17
- system %Q{echo "gem 'playmo', :group => :development" >> ./#{application_name}/Gemfile}
18
30
  system "cd #{application_name} && bundle install"
19
31
 
20
32
  Event.events.fire :after_install
21
33
  Event.events.fire :before_exit
22
34
  end
23
35
 
36
+ private
37
+
38
+ def require_gem
39
+ return unless options[:require]
40
+ gem options[:require]
41
+ #load '/home/tanraya/sandbox/tanraya-playmo/lib/tanraya-playmo.rb'
42
+ #require 'rubygems'
43
+ #gem 'tanraya-playmo', :path => '../../../'
44
+ end
45
+
24
46
  end
25
47
  end