playmo 0.0.6 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/.rspec +2 -0
  2. data/Gemfile +1 -1
  3. data/README.md +9 -45
  4. data/TODO.md +65 -9
  5. data/bin/playmo +6 -0
  6. data/lib/generators/rails/controller_generator.rb +5 -0
  7. data/lib/generators/rails/layout_generator.rb +26 -0
  8. data/lib/generators/rails/scaffold_controller_generator.rb +13 -0
  9. data/lib/generators/rails/templates/controller.rb +11 -0
  10. data/lib/generators/rails/templates/layout.html.erb +46 -0
  11. data/lib/generators/rails/templates/layout.html.haml +26 -0
  12. data/lib/generators/rails/templates/layout.html.slim +26 -0
  13. data/lib/generators/rails/templates/scaffold_controller.rb +56 -0
  14. data/lib/playmo.rb +45 -7
  15. data/lib/playmo/answer.rb +18 -0
  16. data/lib/playmo/choice.rb +52 -0
  17. data/lib/playmo/cli.rb +25 -0
  18. data/lib/playmo/cookbook.rb +83 -0
  19. data/lib/playmo/event.rb +7 -0
  20. data/lib/playmo/options.rb +17 -0
  21. data/lib/playmo/question.rb +59 -0
  22. data/lib/playmo/recipe.rb +50 -0
  23. data/lib/playmo/recipes/_/sample_recipe.rb +46 -0
  24. data/lib/playmo/recipes/application_controller_recipe.rb +24 -0
  25. data/lib/playmo/recipes/application_helper_recipe.rb +18 -0
  26. data/lib/playmo/recipes/assets_recipe.rb +19 -0
  27. data/lib/playmo/recipes/can_can_recipe.rb +0 -0
  28. data/lib/playmo/recipes/capistrano_recipe.rb +25 -0
  29. data/lib/playmo/recipes/compass_recipe.rb +19 -0
  30. data/lib/playmo/recipes/congrats_recipe.rb +20 -0
  31. data/lib/playmo/recipes/devise_recipe.rb +172 -0
  32. data/lib/playmo/recipes/forms_recipe.rb +42 -0
  33. data/lib/playmo/recipes/git_recipe.rb +31 -0
  34. data/lib/playmo/recipes/home_controller_recipe.rb +86 -0
  35. data/lib/playmo/recipes/javascript_framework_recipe.rb +69 -0
  36. data/lib/playmo/recipes/layout_recipe.rb +21 -0
  37. data/lib/playmo/recipes/markup_recipe.rb +34 -0
  38. data/lib/playmo/recipes/rspec_recipe.rb +25 -0
  39. data/lib/playmo/recipes/rvm_recipe.rb +17 -0
  40. data/lib/playmo/recipes/setup_database_recipe.rb +21 -0
  41. data/lib/playmo/recipes/templates/application_controller_recipe/application_controller.rb +54 -0
  42. data/lib/playmo/recipes/templates/application_controller_recipe/internal_error.html.erb +5 -0
  43. data/lib/playmo/recipes/templates/application_controller_recipe/not_found.html.erb +5 -0
  44. data/lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb +118 -0
  45. data/lib/playmo/recipes/templates/assets_recipe/images/bg.jpg +0 -0
  46. data/lib/playmo/recipes/templates/assets_recipe/images/input-bg.gif +0 -0
  47. data/lib/playmo/recipes/templates/assets_recipe/stylesheets/application.css.scss +29 -0
  48. data/lib/playmo/recipes/templates/assets_recipe/stylesheets/media.css.scss +0 -0
  49. data/lib/playmo/recipes/templates/assets_recipe/stylesheets/partials/_constants.css.scss +11 -0
  50. data/lib/playmo/recipes/templates/assets_recipe/stylesheets/partials/_forms.css.scss +134 -0
  51. data/{stylesheets/_playmo_rails.sass → lib/playmo/recipes/templates/assets_recipe/stylesheets/partials/_html5-boilerplate.css.scss} +1 -1
  52. data/lib/playmo/recipes/templates/assets_recipe/stylesheets/partials/_layout.css.scss +264 -0
  53. data/{templates/project/playmo/playmo.scss → lib/playmo/recipes/templates/assets_recipe/stylesheets/partials/_overrides.css.scss} +14 -23
  54. data/lib/playmo/recipes/templates/assets_recipe/stylesheets/partials/_simple_form.css.scss +7 -0
  55. data/{stylesheets/playmo-rails/_fonts.scss → lib/playmo/recipes/templates/assets_recipe/stylesheets/partials/html5-boilerplate/_fonts.css.scss} +5 -6
  56. data/{stylesheets/playmo-rails/_helpers.scss → lib/playmo/recipes/templates/assets_recipe/stylesheets/partials/html5-boilerplate/_helpers.css.scss} +6 -1
  57. data/{stylesheets/playmo-rails/_media.scss → lib/playmo/recipes/templates/assets_recipe/stylesheets/partials/html5-boilerplate/_media.css.scss} +10 -9
  58. data/lib/playmo/recipes/templates/assets_recipe/stylesheets/partials/html5-boilerplate/_reset.css.scss +47 -0
  59. data/{stylesheets/playmo-rails/_styles.scss → lib/playmo/recipes/templates/assets_recipe/stylesheets/partials/html5-boilerplate/_styles.css.scss} +24 -24
  60. data/lib/playmo/recipes/templates/capistrano_recipe/.gitkeep +0 -0
  61. data/lib/playmo/recipes/templates/devise_recipe/.gitkeep +0 -0
  62. data/lib/playmo/recipes/templates/forms_recipe/.gitkeep +0 -0
  63. data/lib/playmo/recipes/templates/home_controller_recipe/_sidebar.html.erb +3 -0
  64. data/lib/playmo/recipes/templates/layout_recipe/application.html.erb +40 -0
  65. data/lib/playmo/recipes/templates/rspec_recipe/.gitkeep +0 -0
  66. data/lib/playmo/recipes/templates/rvm_recipe/.gitkeep +0 -0
  67. data/lib/playmo/silent.rb +17 -0
  68. data/playmo.gemspec +6 -2
  69. data/spec/cookbook_spec.rb +23 -0
  70. data/spec/recipes/home_controller_recipe_spec.rb +13 -0
  71. data/spec/spec_helper.rb +16 -0
  72. data/spec/support/.gitkeep +0 -0
  73. metadata +144 -79
  74. data/lib/app/helpers/playmo_helper.rb +0 -54
  75. data/lib/generators/playmo/USAGE +0 -8
  76. data/lib/generators/playmo/install_generator.rb +0 -166
  77. data/lib/generators/playmo/templates/application.html.erb +0 -56
  78. data/lib/generators/playmo/templates/application_controller.rb +0 -9
  79. data/lib/generators/playmo/templates/application_helper.rb +0 -21
  80. data/lib/generators/playmo/templates/assets.yml +0 -32
  81. data/lib/generators/playmo/templates/deploy.rb +0 -50
  82. data/lib/generators/playmo/templates/jquery/jquery-1.5.2.min.js +0 -16
  83. data/lib/generators/playmo/templates/jquery/rails.js +0 -157
  84. data/lib/generators/playmo/templates/mootools/mootools-core-1.3.1.js +0 -485
  85. data/lib/generators/playmo/templates/mootools/mootools-more-1.3.1.1.js +0 -741
  86. data/lib/generators/playmo/templates/mootools/rails.js +0 -161
  87. data/lib/generators/playmo/templates/tasks/assets.rake +0 -10
  88. data/lib/generators/playmo/templates/tasks/sass.rake +0 -8
  89. data/stylesheets/playmo-rails/_handheld.scss +0 -8
  90. data/stylesheets/playmo-rails/_reset.scss +0 -56
  91. data/templates/project/boilerplate/css/handheld.scss +0 -7
  92. data/templates/project/boilerplate/css/style.scss +0 -141
  93. data/templates/project/boilerplate/files/apple-touch-icon.png +0 -0
  94. data/templates/project/boilerplate/files/crossdomain.xml +0 -25
  95. data/templates/project/boilerplate/files/favicon.ico +0 -0
  96. data/templates/project/boilerplate/files/robots.txt +0 -5
  97. data/templates/project/boilerplate/js/libs/dd_belatedpng.js +0 -13
  98. data/templates/project/boilerplate/js/libs/modernizr-1.7.min.js +0 -2
  99. data/templates/project/google/google.yml +0 -22
  100. data/templates/project/manifest.rb +0 -34
  101. data/templates/project/playmo/article.scss +0 -69
  102. data/templates/project/playmo/icons/outgoing.png +0 -0
  103. data/templates/project/rails/public/stylesheets/layout.scss +0 -20
  104. data/templates/project/rails/public/stylesheets/print.scss +0 -11
  105. data/templates/project/rails/public/stylesheets/screen.scss +0 -14
  106. data/templates/project/rails/public/stylesheets/wysiwyg.scss +0 -19
@@ -0,0 +1,52 @@
1
+ module Playmo
2
+ class Choice < Thor::Shell::Basic
3
+ CAPTION = "\nMake your choice"
4
+ attr_accessor :question, :choice, :accepted_values, :user_input, :caller
5
+
6
+ def initialize(question, caller)
7
+ @question = question
8
+ @caller = caller
9
+ @padding = 0
10
+ @choice = nil
11
+
12
+ if @question.has_answers?
13
+ @accepted_values = 1.upto(@question.answers.size).to_a.map { |value| value.to_s }
14
+ else
15
+ @accepted_values = %w/y n yes no/
16
+ end
17
+ end
18
+
19
+ def make_choice!
20
+ until @accepted_values.include?(@user_input) do
21
+ @user_input = ask render
22
+ @user_input.downcase!
23
+ end
24
+
25
+ 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)
30
+ else
31
+ answer = @question.answers.first
32
+ @caller.send(answer.method_name) if %w/y yes/.include?(@user_input)
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ def render
39
+ if @question.has_answers?
40
+ sentence = @accepted_values.to_sentence(
41
+ :last_word_connector => ' or '
42
+ )
43
+ else
44
+ sentence = "y/n"
45
+ end
46
+
47
+ CAPTION + " (#{sentence}):"
48
+ end
49
+
50
+ alias :to_s :render
51
+ end
52
+ end
@@ -0,0 +1,25 @@
1
+ require 'thor/group'
2
+
3
+ module Playmo
4
+ class Cli < Thor::Group
5
+ include Thor::Actions
6
+
7
+ argument :application_name, :type => :string, :desc => "The name of the rails application"
8
+ desc "Generates a new Rails application with Playmo'"
9
+
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)
15
+
16
+ system %Q{echo "gem 'therubyracer'" >> ./#{application_name}/Gemfile}
17
+ system %Q{echo "gem 'playmo', :path => '../../playmo'" >> ./#{application_name}/Gemfile}
18
+ system "cd #{application_name} && bundle install"
19
+
20
+ Event.events.fire :after_install
21
+ Event.events.fire :before_exit
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,83 @@
1
+ module Playmo
2
+
3
+ # This class contains all registered recipes.
4
+ # You can register own recipe in this class
5
+ class Cookbook
6
+ include Enumerable
7
+ attr_accessor :recipes, :cooked_recipes
8
+
9
+ def self.instance
10
+ @@instance ||= Playmo::Cookbook.new
11
+ end
12
+
13
+ def initialize
14
+ @recipes = []
15
+ @cooked_recipes = []
16
+ end
17
+
18
+ def each
19
+ recipes.each { |x| yield x }
20
+ end
21
+
22
+ def size
23
+ recipes.size
24
+ end
25
+
26
+ def last
27
+ recipes.last
28
+ end
29
+
30
+ def [](i)
31
+ recipes[i]
32
+ end
33
+
34
+ def delete(target)
35
+ recipes.delete target
36
+ end
37
+
38
+ # Is recipe already cooked?
39
+ def cooked?(recipe)
40
+ @cooked_recipes.include?(recipe)
41
+ end
42
+
43
+ # Adds the new recipe before the specified existing recipe in the Cookbook stack.
44
+ def insert(existing_recipe, new_recipe)
45
+ index = assert_index(existing_recipe, :before)
46
+ recipes.insert(index, new_recipe)
47
+ end
48
+
49
+ alias_method :insert_before, :insert
50
+
51
+ # Adds the new recipe after the specified existing recipe in the Cookbook stack.
52
+ def insert_after(existing_recipe, new_recipe)
53
+ index = assert_index(existing_recipe, :after)
54
+ insert(index + 1, new_recipe)
55
+ end
56
+
57
+ # Adds the new recipe at the bottom of the Cookbook stack.
58
+ def use(new_recipe)
59
+ recipes.push(new_recipe)
60
+ end
61
+
62
+ def cook_recipes!(application_name)
63
+ prepared_recipes = []
64
+
65
+ recipes.each do |recipe|
66
+ prepared_recipes << recipe.new
67
+ end
68
+
69
+ prepared_recipes.each do |recipe|
70
+ recipe.cook!(application_name)
71
+ @cooked_recipes << recipe
72
+ end
73
+ end
74
+
75
+ protected
76
+
77
+ def assert_index(index, where)
78
+ i = index.is_a?(Integer) ? index : recipes.index(index)
79
+ raise "No such recipe to insert #{where}: #{index.inspect}" unless i
80
+ i
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,7 @@
1
+ require 'ruby_events'
2
+
3
+ module Playmo
4
+ module Event
5
+
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ require 'singleton'
2
+
3
+ module Playmo
4
+ class Options
5
+ include Singleton
6
+ attr_accessor :options_hash
7
+
8
+ def set(key, value)
9
+ @options_hash ||= {}
10
+ @options_hash[key.to_sym] = value
11
+ end
12
+
13
+ def get(key)
14
+ @options_hash[key.to_sym]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,59 @@
1
+ module Playmo
2
+ class Question < Thor::Shell::Basic
3
+ attr_accessor :answers, :choice, :question_text, :caller
4
+
5
+ def initialize(arg, &block)
6
+ @question_text, method_name = arg, nil
7
+ @answers ||= []
8
+ @padding = 0
9
+
10
+ # Question with no answers
11
+ if arg.respond_to? :keys
12
+ @question_text, method_name = arg.first.first, arg.first.last
13
+ answer(nil => method_name)
14
+ end
15
+
16
+ # Multiple answers
17
+ self.instance_eval(&block) if block_given?
18
+ end
19
+
20
+ def set_caller(recipe)
21
+ @caller = recipe
22
+ end
23
+
24
+ def answer(arg)
25
+ @answers << Playmo::Answer.new(arg.first.first, arg.first.last, @answers.size + 1)
26
+ end
27
+
28
+ def has_answers?
29
+ @answers.size > 1
30
+ end
31
+
32
+ def ask_question!
33
+ say render
34
+ end
35
+
36
+ # Render question with answers
37
+ def render
38
+ result = "\n#{@question_text}"
39
+
40
+ if has_answers?
41
+ result += ":\n\n"
42
+ num = 1
43
+ @answers.each do |answer|
44
+ result += answer.render
45
+ num += 1
46
+ end
47
+ else
48
+ result += "\n"
49
+ end
50
+
51
+ # Create choice
52
+ @choice = Playmo::Choice.new(self, @caller)
53
+
54
+ result
55
+ end
56
+
57
+ alias :to_s :render
58
+ end
59
+ end
@@ -0,0 +1,50 @@
1
+ require 'rails/generators'
2
+
3
+ module Playmo
4
+ # Base class for all recipes
5
+ class Recipe < Rails::Generators::Base
6
+ attr_accessor :question_instance, :silents, :application_name
7
+
8
+ # Приготовление рецепта
9
+ def cook!(application_name)
10
+ self.destination_root = application_name
11
+ self.application_name = application_name
12
+ setup
13
+
14
+ unless question_instance.nil?
15
+ question_instance.set_caller(self)
16
+
17
+ # Ask question
18
+ question_instance.ask_question!
19
+
20
+ # Ask for choice and make choice
21
+ question_instance.choice.make_choice!
22
+ end
23
+
24
+ # Execute all silents
25
+ unless silents.nil?
26
+ silents.each do |silent|
27
+ silent.set_caller(self)
28
+ silent.execute!
29
+ end
30
+ end
31
+ end
32
+
33
+ def question(arg, &block)
34
+ @question_instance = Playmo::Question.new(arg, &block)
35
+ end
36
+
37
+ def silently(&block)
38
+ @silents ||= []
39
+ @silents << Playmo::Silent.new(&block)
40
+ end
41
+
42
+ def store(*args)
43
+ Options.instance.set(*args)
44
+ end
45
+
46
+ def retrieve(*args)
47
+ Options.instance.get(*args)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,46 @@
1
+ module Playmo
2
+ module Generators
3
+ module Recipes
4
+ class SampleRecipe < Playmo::Recipe
5
+ # Cook the recipe
6
+ # TODO: Add rspec tests
7
+ # TODO: Recipe with more than one question
8
+ # TODO: You can create own gem and redefine Playmo behavior by removing or adding recipes
9
+ # TODO: Create a web service built on top of Playmo to prepare new app and putting it to Github or download in archive
10
+ # TODO: A playmo bin file that generate rails app and do all the stuff as altennative to manually installing rails app and include playmo into this app
11
+ # TODO: Require playmo to the app only when in development mode
12
+ # TODO: Copy Playmo view heplers into the app
13
+
14
+ def initialize
15
+ silently do
16
+ # do something without any questions
17
+ end
18
+
19
+ question "What's up Docz?" => :do_something_for_doc
20
+
21
+ def do_something_for_doc
22
+ # do something for Doc
23
+ end
24
+
25
+ question "What's up Docx?" do
26
+ answer "So-so" => :so_so
27
+ answer "Nice!" => :nice
28
+ end
29
+
30
+ question "What's up Docy?" do
31
+ answer "So-so" do
32
+ # do something
33
+ end
34
+
35
+ answer "Nice!" do
36
+ # do something
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ # Write down this recipe to our Cookbook if it's available
46
+ # Playmo::Cookbook.instance.use(Playmo::Generators::Recipes::SampleRecipe.new) if defined?(Playmo::Cookbook)
@@ -0,0 +1,24 @@
1
+ module Playmo
2
+ module Recipes
3
+ class ApplicationControllerRecipe < Playmo::Recipe
4
+ source_root File.expand_path('../templates/application_controller_recipe', __FILE__)
5
+
6
+ def setup
7
+ silently do
8
+ remove_file 'app/controllers/application_controller.rb'
9
+ copy_file 'application_controller.rb', 'app/controllers/application_controller.rb'
10
+ empty_directory "app/views/application"
11
+ copy_file "internal_error.html.erb", "app/views/application/internal_error.html.erb"
12
+ copy_file "not_found.html.erb", "app/views/application/not_found.html.erb"
13
+
14
+ # To catch routing errors
15
+ route 'match "*catch_all" => "application#not_found"'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ # Write down this recipe to our Cookbook if it's available
23
+ require File.dirname(__FILE__) + '/assets_recipe'
24
+ Playmo::Cookbook.instance.insert_after(Playmo::Recipes::AssetsRecipe, Playmo::Recipes::ApplicationControllerRecipe) if defined?(Playmo::Cookbook)
@@ -0,0 +1,18 @@
1
+ module Playmo
2
+ module Recipes
3
+ class ApplicationHelperRecipe < Playmo::Recipe
4
+ source_root File.expand_path('../templates/application_helper_recipe', __FILE__)
5
+
6
+ def setup
7
+ silently do
8
+ remove_file 'app/helpers/application_helper.rb'
9
+ copy_file 'application_helper.rb', 'app/helpers/application_helper.rb'
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ # Write down this recipe to our Cookbook if it's available
17
+ require File.dirname(__FILE__) + '/home_controller_recipe'
18
+ Playmo::Cookbook.instance.insert_after(Playmo::Recipes::HomeControllerRecipe, Playmo::Recipes::ApplicationHelperRecipe) if defined?(Playmo::Cookbook)
@@ -0,0 +1,19 @@
1
+ module Playmo
2
+ module Recipes
3
+ class AssetsRecipe < Playmo::Recipe
4
+ source_root File.expand_path('../templates/assets_recipe', __FILE__)
5
+
6
+ def setup
7
+ silently do
8
+ directory 'images/', 'app/assets/images/'
9
+ directory 'stylesheets/', 'app/assets/stylesheets/'
10
+ remove_file 'app/assets/stylesheets/application.css'
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ # Write down this recipe to our Cookbook if it's available
18
+ require File.dirname(__FILE__) + '/markup_recipe'
19
+ Playmo::Cookbook.instance.insert_after(Playmo::Recipes::MarkupRecipe, Playmo::Recipes::AssetsRecipe) if defined?(Playmo::Cookbook)
File without changes
@@ -0,0 +1,25 @@
1
+ module Playmo
2
+ module Recipes
3
+ class CapistranoRecipe < Playmo::Recipe
4
+ source_root File.expand_path('../templates/capistrano_recipe', __FILE__)
5
+
6
+ def setup
7
+ question "Would you like to deploy project with Capistrano?" => :install_capistrano
8
+ end
9
+
10
+ def install_capistrano
11
+ gem 'capistrano'
12
+
13
+ # TODO: Copy deploy.rb
14
+
15
+ Event.events.listen(:after_install) do |event_data|
16
+ capify!
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ # Write down this recipe to our Cookbook if it's available
24
+ require File.dirname(__FILE__) + '/rspec_recipe'
25
+ Playmo::Cookbook.instance.insert_after(Playmo::Recipes::RspecRecipe, Playmo::Recipes::CapistranoRecipe) if defined?(Playmo::Cookbook)
@@ -0,0 +1,19 @@
1
+ module Playmo
2
+ module Recipes
3
+ class CompassRecipe < Playmo::Recipe
4
+ source_root File.expand_path('../templates/compass_recipe', __FILE__)
5
+
6
+ def setup
7
+ question "Would you like to use Compass in this project?" => :install_compass
8
+ end
9
+
10
+ def install_compass
11
+ gem "compass", "~> 0.12.alpha.0"
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ # Write down this recipe to our Cookbook if it's available
18
+ require File.dirname(__FILE__) + '/application_controller_recipe'
19
+ Playmo::Cookbook.instance.insert_after(Playmo::Recipes::ApplicationControllerRecipe, Playmo::Recipes::CompassRecipe) if defined?(Playmo::Cookbook)