sanji 1.0.0.pre → 1.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db57a4e0739187f622d2dfd0e997135ac62bb85d
4
- data.tar.gz: fa9dc9a29f35da36a0cd46150927a579bfda400e
3
+ metadata.gz: 4f13d7a1af1f0d2edf708a58d578a712f907fee0
4
+ data.tar.gz: c7bad2377c6be921fb2eebcb0be840dffe3cfb61
5
5
  SHA512:
6
- metadata.gz: 399f7e0e08d027a55c717a2bdcd0522adb6433e9b79d3f369a0ee14f5d8c3ddc583f584daaba233bfc9ec25f707bcbfe7cc2a57f0d247ce5c07bbf10d7c05e61
7
- data.tar.gz: 18aed75ec1c1fe017eb316bf603c206ed6e6ac705c1630aec79232743ede32923a7200eb40c1412ec8cd8ff159d69c5660f1e5952b4f94f25547f2ffc0b378c9
6
+ metadata.gz: 699d5133e49fd48fbe0fa8f5ea938e84edb50423503ce924ce8934c97c6cf4364ea138882d79cf0bbfb89fa1a1ffba36fea06237cd8d441947ba37a49bdcd3de
7
+ data.tar.gz: 6261997f340b575fee6db4c7b1cbd2df0b4d148bd899eceab473c3583d7cce29d5c6d67d41a5e3fd1cdf52de1426464f70e4aa3191b81e441fd806c86976c370
data/README.md CHANGED
@@ -1,3 +1,82 @@
1
1
  # sanji
2
2
 
3
+ Customized Rails application generator.
4
+ Inspired by [suspenders](https://github.com/thoughtbot/suspenders) and [rails_apps_composer](https://github.com/RailsApps/rails_apps_composer) gems.
5
+
3
6
  ![sanji](http://icons.iconarchive.com/icons/crountch/one-piece-character/256/Sanji-icon.png)
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ gem install sanji
12
+ ```
13
+
14
+ ## Basic usage
15
+
16
+ ```
17
+ sanji app_name
18
+ ```
19
+
20
+ ## Local Recipe
21
+
22
+ ```ruby
23
+ class Sanji::Locals::MyRecipe < Sanji::Recipe
24
+
25
+ def prompt
26
+ # return a string (boolean question) to make this recipe optional
27
+ end
28
+
29
+ def after_create
30
+ # execute after app is created
31
+ end
32
+
33
+ def after_bundle
34
+ # execute after bundle
35
+ end
36
+
37
+ def after_everything
38
+ # execute after "after_bundle"
39
+ end
40
+
41
+ end
42
+ ```
43
+
44
+ ## Local Setup
45
+
46
+ - `.bash_profile`
47
+ ```
48
+ export SANJI_HOME=/path/to/sanji/
49
+ ```
50
+
51
+ - `/path/to/sanji/sanji.yml`
52
+ ```ruby
53
+ cookbook: cookbook_name
54
+ recipes: /path/to/recipes
55
+
56
+ cookbooks:
57
+ cookbook_name:
58
+ - recipe_name
59
+ - other_recipe_name
60
+ - another_recipe
61
+
62
+ my_cookbook:
63
+ - my_recipe
64
+ ```
65
+
66
+ ## Inclusions
67
+
68
+ - Gems
69
+ - pg - PostgreSQL adapter.
70
+ - seedbank - Organize seeds.
71
+ - annotate - Model annotations.
72
+ - figaro - Read environment variables.
73
+ - haml-rails - View template engine.
74
+ - draper - Decorator for views.
75
+ - reform - Form objects.
76
+ - virtus - Coercion for Form objects.
77
+ - bootstrap-sass - Twitter Bootstrap CSS and Javascripts (optional).
78
+ - normalize-rails - CSS Reset (if bootstrap is not selected).
79
+ - paperclip - Attachments for models.
80
+ - kaminari - Pagination.
81
+ - thin - Development web server.
82
+ - quiet_assets - Prevent asset logs.
@@ -1,53 +1,51 @@
1
1
  module Sanji
2
2
  class AppBuilder < Rails::AppBuilder
3
3
 
4
- RECIPES = [
5
- :Setup,
6
- :Annotate,
7
- :Draper,
8
- :Figaro,
9
- :Haml,
10
- :Paloma,
11
- :Postgresql,
12
- :Reform,
13
- :Seedbank,
14
- :Frontend,
15
- :SimpleGems,
16
- :Controllers,
17
- :Devise,
18
- :Cleanup
19
- ]
20
-
21
4
  def after_create_tasks
22
- RECIPES.each do |name|
23
- self.get_recipe_instance(name).run_after_create
5
+ self.setup_recipe.run_after_create
6
+
7
+ self.recipe_classes.each do |recipe_class|
8
+ self.get_recipe_instance(recipe_class).run_after_create
24
9
  end
10
+
11
+ self.cleanup_recipe.run_after_create
25
12
  end
26
13
 
27
14
  def after_bundle_tasks
28
- RECIPES.each do |name|
29
- self.get_recipe_instance(name).run_after_bundle
15
+ self.setup_recipe.run_after_bundle
16
+
17
+ self.recipe_classes.each do |recipe_class|
18
+ self.get_recipe_instance(recipe_class).run_after_bundle
30
19
  end
20
+
21
+ self.cleanup_recipe.run_after_bundle
31
22
  end
32
23
 
33
24
  def after_everything_tasks
34
- RECIPES.each do |name|
35
- self.get_recipe_instance(name).run_after_everything
25
+ self.setup_recipe.run_after_everything
26
+
27
+ self.recipe_classes.each do |recipe_class|
28
+ self.get_recipe_instance(recipe_class).run_after_everything
36
29
  end
30
+
31
+ self.cleanup_recipe.run_after_everything
37
32
  end
38
33
 
39
34
 
40
35
 
41
36
  protected
42
37
 
43
- def get_recipe_instance name
44
- recipe = self.recipe_instances[name]
38
+ def recipe_classes
39
+ Options.instance.recipe_classes
40
+ end
41
+
42
+ def get_recipe_instance recipe_class
43
+ recipe = self.recipe_instances[recipe_class.name.to_sym]
45
44
  return recipe if recipe
46
45
 
47
- recipe_class = ::Sanji::Recipes.const_get name
48
46
  recipe = recipe_class.new self
49
47
 
50
- self.recipe_instances[name] = recipe
48
+ self.recipe_instances[recipe_class.name.to_sym] = recipe
51
49
  recipe
52
50
  end
53
51
 
@@ -55,5 +53,13 @@ module Sanji
55
53
  @recipe_instances ||= {}
56
54
  end
57
55
 
56
+ def setup_recipe
57
+ @setup_recipe ||= Sanji::Recipes::Setup.new(self)
58
+ end
59
+
60
+ def cleanup_recipe
61
+ @cleanup_recipe ||= Sanji::Recipes::Cleanup.new(self)
62
+ end
63
+
58
64
  end
59
65
  end
@@ -0,0 +1,33 @@
1
+ require 'yaml'
2
+
3
+ class Sanji::Config
4
+
5
+ attr_reader :contents
6
+
7
+ def initialize filename = nil
8
+ @contents = YAML.load_file(filename) if filename
9
+ end
10
+
11
+ def cookbook
12
+ self.contents['cookbook'] if self.contents
13
+ end
14
+
15
+ def cookbooks
16
+ self.contents['cookbooks'] if self.contents
17
+ end
18
+
19
+ def has_cookbook? name
20
+ return false unless self.contents
21
+ self.cookbooks.has_key? name.to_s
22
+ end
23
+
24
+ def recipes
25
+ return [] unless self.contents
26
+ self.cookbooks[self.cookbook]
27
+ end
28
+
29
+ def recipes_path
30
+ self.contents['recipes'] if self.contents
31
+ end
32
+
33
+ end
@@ -0,0 +1,91 @@
1
+ class Sanji::Options
2
+
3
+ DEFAULT_HOME_PATH = "#{File.dirname(__FILE__)}/../"
4
+ HOME_PATH_ENV_VARIABLE = 'SANJI_HOME'
5
+
6
+ CONFIG_FILENAME = 'sanji.yml'
7
+ SANJI_ITEMS_PREFIX = '_'
8
+
9
+
10
+ def self.instance
11
+ @instance ||= self.new
12
+ end
13
+
14
+
15
+
16
+ def initialize
17
+ @default_config = Sanji::Config.new "#{DEFAULT_HOME_PATH}/#{CONFIG_FILENAME}"
18
+ @user_config = self.fetch_user_config
19
+ end
20
+
21
+ def user_recipes_path
22
+ return nil if self.user_home_path.blank?
23
+ "#{self.user_home_path}/#{@user_config.recipes_path}"
24
+ end
25
+
26
+ def cookbook
27
+ @cookbook ||= @user_config.cookbook || @default_config.cookbook
28
+ end
29
+
30
+ def sanji_cookbook?
31
+ self.is_sanji_item? self.cookbook
32
+ end
33
+
34
+ def recipe_classes
35
+ @recipes ||=
36
+ self.cookbook_recipe_names.map do |recipe_name|
37
+ self.get_recipe_class recipe_name
38
+ end
39
+ end
40
+
41
+ def cookbook_recipe_names
42
+ return @cookbook_entry if @cookbook_entry
43
+
44
+ cookbook_valid_name = self.valid_item_name self.cookbook
45
+
46
+ @cookbook_entry =
47
+ if self.sanji_cookbook?
48
+ @default_config.cookbooks[cookbook_valid_name]
49
+ else
50
+ @user_config.cookbooks[cookbook_valid_name]
51
+ end
52
+ end
53
+
54
+
55
+ protected
56
+
57
+ def user_home_path
58
+ @user_home_path ||= ENV[HOME_PATH_ENV_VARIABLE]
59
+ end
60
+
61
+ def fetch_user_config
62
+ filename =
63
+ user_home_path ? "#{self.user_home_path}/#{CONFIG_FILENAME}" : nil
64
+
65
+ Sanji::Config.new filename
66
+ end
67
+
68
+ def is_sanji_item? item_name
69
+ item_name.start_with? SANJI_ITEMS_PREFIX
70
+ end
71
+
72
+ def valid_item_name item_name
73
+ if self.is_sanji_item? item_name
74
+ return item_name.sub SANJI_ITEMS_PREFIX, ''
75
+ end
76
+
77
+ item_name
78
+ end
79
+
80
+ def get_recipe_class name
81
+ recipe_valid_name = self.valid_item_name name
82
+ recipe_class_name = recipe_valid_name.camelize
83
+
84
+ if self.is_sanji_item? name
85
+ Sanji::Recipes.const_get recipe_class_name
86
+ else
87
+ Sanji::Locals.const_get recipe_class_name
88
+ end
89
+ end
90
+
91
+ end
data/lib/sanji/recipe.rb CHANGED
@@ -4,21 +4,29 @@ class Sanji::Recipe
4
4
 
5
5
  def initialize builder
6
6
  @a = Sanji::Assistant.new self, builder
7
+ @disabled = false
7
8
  end
8
9
 
9
10
  def run_after_create
11
+ @disabled = a.no?(self.prompt) if self.prompt.present?
12
+ return if @disabled
13
+
10
14
  a.log_start :after_create
11
15
  self.after_create
12
16
  a.log_end :after_create
13
17
  end
14
18
 
15
19
  def run_after_bundle
20
+ return if @disabled
21
+
16
22
  a.log_start :after_bundle
17
23
  self.after_bundle
18
24
  a.log_end :after_bundle
19
25
  end
20
26
 
21
27
  def run_after_everything
28
+ return if @disabled
29
+
22
30
  a.log_start :after_everything
23
31
  self.after_everything
24
32
  a.log_end :after_everything
@@ -33,4 +41,7 @@ class Sanji::Recipe
33
41
  def after_everything
34
42
  end
35
43
 
44
+ def prompt
45
+ end
46
+
36
47
  end
@@ -1,5 +1,9 @@
1
1
  class Sanji::Recipes::Draper < Sanji::Recipe
2
2
 
3
+ def prompt
4
+ 'Do you want to use Draper?'
5
+ end
6
+
3
7
  def after_create
4
8
  a.add_gem 'draper'
5
9
  a.generator :decorator, false
data/lib/sanji.rb CHANGED
@@ -2,24 +2,37 @@ module Sanji
2
2
  module Recipes
3
3
  end
4
4
 
5
+ module Locals
6
+ end
7
+
5
8
  module Utilities
6
9
  end
7
10
  end
8
11
 
12
+ require 'sanji/config'
13
+ require 'sanji/options'
14
+
9
15
  # Require all utilities
10
16
  Dir["#{File.dirname(__FILE__)}/sanji/utilities/*.rb"].each do |filename|
11
17
  require filename.sub('.rb', '')
12
18
  end
13
19
 
14
-
15
20
  require 'sanji/assistant'
16
21
  require 'sanji/recipe'
22
+ require 'sanji/app_generator'
23
+ require 'sanji/app_builder'
17
24
 
18
25
  # Require all recipes
19
26
  Dir["#{File.dirname(__FILE__)}/sanji/recipes/*.rb"].each do |filename|
20
27
  require filename.sub('.rb', '')
21
28
  end
22
29
 
23
- require 'sanji/app_generator'
24
- require 'sanji/app_builder'
30
+ # Require user recipes
31
+ if Sanji::Options.instance.user_recipes_path
32
+ Dir["#{Sanji::Options.instance.user_recipes_path}/*.rb"].each do |filename|
33
+ require filename.sub('.rb', '')
34
+ end
35
+ end
36
+
37
+
25
38
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanji
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre
4
+ version: 1.0.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Paragua
@@ -23,6 +23,8 @@ files:
23
23
  - lib/sanji/app_builder.rb
24
24
  - lib/sanji/app_generator.rb
25
25
  - lib/sanji/assistant.rb
26
+ - lib/sanji/config.rb
27
+ - lib/sanji/options.rb
26
28
  - lib/sanji/recipe.rb
27
29
  - lib/sanji/recipes/annotate.rb
28
30
  - lib/sanji/recipes/cleanup.rb