rails_assist 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
@@ -17,13 +17,13 @@ require 'rails_assist/namespaces'
17
17
 
18
18
  module RailsAssist
19
19
  def self.artifacts
20
- [:observer, :controller, :helper, :mailer, :model, :migration, :permit]
20
+ [:observer, :controller, :helper, :mailer, :model, :migration, :permit, :asset]
21
21
  end
22
22
 
23
23
  def self.specials type=nil
24
24
  case type
25
25
  when :config
26
- [:initializer, :locale]
26
+ [:initializer, :locale, :config]
27
27
  when :public
28
28
  [:stylesheet, :javascript]
29
29
  else
@@ -31,7 +31,7 @@ module RailsAssist
31
31
  [:initializer, :locale] + [:stylesheet, :javascript]
32
32
  end
33
33
  end
34
-
34
+
35
35
  class << self
36
36
  attr_accessor :debug_on
37
37
  end
@@ -1,13 +1,13 @@
1
- module RailsAssist
2
- module App
1
+ module RailsAssist
2
+ module App
3
3
  def create_empty_tmp *dir_types
4
4
  dir_types.flatten.each do |dir_type|
5
5
  dir = RailsAssist::Directory.rails_dir_for(dir_type)
6
6
  FileUtils.mkdir_p dir
7
7
  end
8
8
  end
9
-
10
- extend self
11
- end
9
+
10
+ extend self
11
+ end
12
12
  end
13
13
 
@@ -1,34 +1,34 @@
1
1
  module RailsAssist::Artifact
2
2
  module Methods
3
3
  def helper_list
4
- RailsAssist.artifacts + [:view]
4
+ RailsAssist.artifacts + [:view, :asset]
5
5
  end
6
6
 
7
7
  def app_artifacts
8
- [:controller, :mailer, :helper, :view, :model, :permit, :license, :validator]
8
+ [:controller, :mailer, :helper, :view, :model, :permit, :license, :validator, :asset]
9
9
  end
10
-
10
+
11
11
  def rails_artifacts
12
12
  @rails_artifacts ||= begin
13
- files_methods = RailsAssist::Artifact::Files.instance_methods
13
+ files_methods = RailsAssist::Artifact::Files.instance_methods
14
14
  files_symbols = files_methods.grep(/_files$/).map{|f| f.to_s.gsub(/^(.*)_files/, '\1').to_sym }
15
15
 
16
- # dir_methods = RailsAssist::Artifact::Directory.instance_methods
16
+ # dir_methods = RailsAssist::Artifact::Directory.instance_methods
17
17
  # dir_symbols = dir_methods.map{|dir| dir.to_s.gsub(/^(.*)_dir/, '\1').to_sym }
18
18
  dir_symbols = []
19
-
19
+
20
20
  (files_symbols + dir_symbols).uniq
21
- end
21
+ end
22
22
  end
23
23
 
24
24
  def valid_artifact? type
25
25
  rails_artifacts.include?(type)
26
- end
27
- end
28
-
26
+ end
27
+ end
28
+
29
29
  extend Methods
30
- include Methods
31
- end
30
+ include Methods
31
+ end
32
32
 
33
33
 
34
- require_all File.dirname(__FILE__) + '/artifact'
34
+ require_all File.dirname(__FILE__) + '/artifact'
@@ -3,7 +3,7 @@ module RailsAssist::Artifact
3
3
  module Methods
4
4
  DIR = RailsAssist::Directory
5
5
  APP_DIR = RailsAssist::Directory::App
6
-
6
+
7
7
  # :controller, :mailer, :helper, :view, :model, :permit
8
8
  #
9
9
  # controller_dir, mailer_dir ...
@@ -17,17 +17,17 @@ module RailsAssist::Artifact
17
17
  def #{name}_dir options={}
18
18
  #{name}_dirpath(options).dir
19
19
  end
20
- }
21
- end
22
-
20
+ }
21
+ end
22
+
23
23
  # initializer_dir, locale_dir
24
- # stylesheet_dir, javascript_dir
24
+ # stylesheet_dir, javascript_dir
25
25
  {:config => RailsAssist.specials(:config), :public => RailsAssist.specials(:public)}.each_pair do |container, names|
26
26
  names.each do |name|
27
- class_eval %{
27
+ class_eval %{
28
28
  def #{name}_dirpath options={}
29
29
  RailsAssist::Directory.#{container}_dir_for(:#{name.to_s.pluralize}, options).path
30
- end
30
+ end
31
31
 
32
32
  def #{name}_dir options={}
33
33
  #{name}_dirpath(options).dir
@@ -37,13 +37,23 @@ module RailsAssist::Artifact
37
37
  end
38
38
 
39
39
  [:stylesheet, :javascript].each do |name|
40
- class_eval %{
40
+ class_eval %{
41
41
  def #{name}_dirpath options={}
42
42
  RailsAssist::Directory.public_dir_for(:#{name.to_s.pluralize}, options).path
43
43
  end
44
44
  }
45
45
  end
46
-
46
+
47
+ {:javascripts => [:js, :coffee], :stylesheets => [:scss, :sass]}.each_pair do |folder, exts|
48
+ exts.each do |ext|
49
+ class_eval %{
50
+ def #{ext}_asset_dirpaths options={}
51
+ [asset_dirpath, '#{folder}'].file_join
52
+ end
53
+ }
54
+ end
55
+ end
56
+
47
57
  def migration_dirpath options={}
48
58
  [DIR.db_dirpath(options), 'migrate'].file_join
49
59
  end
@@ -51,7 +61,7 @@ module RailsAssist::Artifact
51
61
  def migration_dir options={}
52
62
  migration_dirpath(options).dir
53
63
  end
54
-
64
+
55
65
  def observer_dirpath options={}
56
66
  model_dir(options).path
57
67
  end
@@ -1,31 +1,31 @@
1
1
  require 'sugar-high/regexp'
2
2
 
3
3
  module RailsAssist::Artifact
4
- module Files
5
- module Methods
4
+ module Files
5
+ module Methods
6
6
  [:model].each do |name|
7
7
  class_eval %{
8
8
  def #{name}_filepaths expr=nil
9
9
  files = RailsAssist::Files.rails_app_files(:#{name.to_s.pluralize}).grep_it expr
10
10
  yield files if block_given?
11
11
  files
12
- end
12
+ end
13
13
 
14
14
  def #{name}_files expr=nil
15
15
  files = #{name}_filepaths(expr).to_files
16
16
  yield files if block_given?
17
17
  files
18
- end
18
+ end
19
19
  }
20
20
  end
21
21
 
22
- [:initializer, :locale].each do |name|
22
+ [:initializer, :locale, :config].each do |name|
23
23
  class_eval %{
24
24
  def #{name}_filepaths expr=nil
25
25
  files = RailsAssist::Files.rails_app_files(:#{name.to_s.pluralize}).grep_it expr
26
26
  yield files if block_given?
27
27
  files
28
- end
28
+ end
29
29
  }
30
30
  end
31
31
 
@@ -36,39 +36,65 @@ module RailsAssist::Artifact
36
36
  files = RailsAssist::Files.rails_app_files(:#{name.to_s.pluralize}, :pattern => '**/*_#{name}.rb').grep_it expr
37
37
  yield files if block_given?
38
38
  files
39
- end
39
+ end
40
40
 
41
41
  def #{name}_files expr=nil
42
42
  files = #{name}_filepaths(expr).to_files
43
43
  yield files if block_given?
44
44
  files
45
- end
45
+ end
46
46
  }
47
- end
47
+ end
48
48
 
49
- def view_filepaths *args
50
- expr, model_name = Helper.get_view_args args
49
+ def view_filepaths *args
50
+ expr, name = Helper.get_view_args args
51
51
  ext = last_option(args)[:template_language] || 'erb'
52
- pattern = model_name ? "#{model_name.to_s.pluralize}/*.#{ext}*" : "**/*.#{ext}*"
52
+ pattern = name ? "#{name.to_s.pluralize}/*.#{ext}*" : "**/*.#{ext}*"
53
53
  files = RailsAssist::Files.rails_app_files(:views, :pattern => pattern).grep_it expr
54
54
  yield files if block_given?
55
- files
55
+ files
56
56
  end
57
57
 
58
58
  def view_files *args
59
59
  files = view_filepaths(args).to_files
60
60
  yield files if block_given?
61
61
  files
62
- end
62
+ end
63
+
64
+ def asset_filepaths *args
65
+ expr, name = Helper.get_asset_args args
66
+ ext = last_option(args)[:ext]
67
+ pattern = name ? "#{name.to_s.pluralize}/*.#{ext}*" : "**/*.#{ext}*"
68
+ files = RailsAssist::Files.rails_app_files(:assets, :pattern => pattern).grep_it expr
69
+ yield files if block_given?
70
+ files
71
+ end
72
+
73
+ def asset_files *args
74
+ files = asset_filepaths(args).to_files
75
+ yield files if block_given?
76
+ files
77
+ end
78
+
79
+ [:js, :css, :scss, :sass].each do |name|
80
+ class_eval %{
81
+ def #{name}_asset_filepaths *args
82
+ asset_files args, :ext => :#{name}
83
+ end
63
84
 
85
+ def #{name}_asset_files *args
86
+ asset_filepaths(args).to_files
87
+ end
88
+ }
89
+ end
64
90
 
65
91
  [:erb, :haml, :slim].each do |name|
66
92
  class_eval %{
67
- def #{name}_view_filepaths *args
93
+ def #{name}_view_filepaths *args
68
94
  view_files args, :template_language => :#{name}
69
95
  end
70
96
 
71
- def #{name}_view_files *args
97
+ def #{name}_view_files *args
72
98
  view_filepaths(args).to_files
73
99
  end
74
100
  }
@@ -77,19 +103,22 @@ module RailsAssist::Artifact
77
103
  extend Methods
78
104
  include Methods
79
105
 
80
- module Helper
81
- def self.get_view_args args
82
- args = args.flatten
83
- first_arg = args.first
84
- case first_arg
85
- when Regexp
86
- expr = first_arg
87
- when String, Symbol
88
- _model = first_arg
106
+ module Helper
107
+ class << self
108
+ def get_view_args args
109
+ args = args.flatten
110
+ first_arg = args.first
111
+ case first_arg
112
+ when Regexp
113
+ expr = first_arg
114
+ when String, Symbol
115
+ _model = first_arg
116
+ end
117
+ expr = args[1] if args.size > 1 && args[1].kind_of?(Regexp)
118
+ [expr, _model]
89
119
  end
90
- expr = args[1] if args.size > 1 && args[1].kind_of?(Regexp)
91
- [expr, _model]
92
- end
120
+ alias_method :get_asset_args, :get_view_args
121
+ end
93
122
  end
94
123
  end
95
- end
124
+ end
@@ -1,7 +1,7 @@
1
1
  module RailsAssist::Artifact
2
2
  module Path
3
- include RailsAssist::Artifact::Directory
4
-
3
+ include RailsAssist::Artifact::Directory
4
+
5
5
  def artifact_path name, type, options={}
6
6
  dir = send :"#{type}_dirpath", options
7
7
  File.join(dir, "#{name}#{type_postfix type}.rb")
@@ -13,4 +13,4 @@ module RailsAssist::Artifact
13
13
  "_#{type}" if ![:model].include?(type)
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -2,14 +2,14 @@ require_all File.dirname(__FILE__) + '/directory'
2
2
  require 'rails_assist/artifact'
3
3
 
4
4
  module RailsAssist
5
- module Directory
5
+ module Directory
6
6
  class << self
7
7
  attr_accessor :rails_root
8
-
8
+
9
9
  def method_missing(sym, *args, &block)
10
10
  RailsAssist::Artifact::Directory.send sym
11
11
  end
12
- end
12
+ end
13
13
 
14
14
  include Root
15
15
  extend Root
@@ -17,15 +17,15 @@ module RailsAssist
17
17
  include App
18
18
  extend App
19
19
 
20
- include Container
20
+ include Container
21
21
  extend Container
22
-
22
+
23
23
  # dir_for helpers
24
24
  # -------------------
25
25
 
26
- module Methods
27
- DIR = RailsAssist::Artifact::Directory
28
-
26
+ module Methods
27
+ DIR = RailsAssist::Artifact::Directory
28
+
29
29
  # :app, :config, :db, :public, :lib, :log, :doc, :test, :spec
30
30
  #
31
31
  # app_dir, config_dir ...
@@ -36,35 +36,35 @@ module RailsAssist
36
36
  raise "Rails Root dir not defined" if _root_dir.nil?
37
37
  ::File.join(_root_dir, '#{name}')
38
38
  end
39
-
39
+
40
40
  def #{name}_dir options={}
41
41
  #{name}_dirpath(options).dir
42
42
  end
43
- }
44
- end
45
-
43
+ }
44
+ end
45
+
46
46
  def rails_dir_for type, options={}
47
47
  raise ArgumentError, '#rails_dir_for takes a dir type argument' if !type
48
- dir_method = "#{type}_dir"
48
+ dir_method = "#{type}_dirpath"
49
49
  return send(dir_method, options) if respond_to?(dir_method)
50
50
  DIR.send(dir_method, options) if DIR.respond_to?(dir_method)
51
51
  end
52
52
 
53
53
  def app_dir_for type, options={}
54
54
  ::File.join(app_dirpath(options), type.to_s.pluralize)
55
- end
55
+ end
56
56
 
57
57
  def config_dir_for type, options={}
58
58
  ::File.join(config_dirpath(options), type.to_s.pluralize)
59
- end
59
+ end
60
60
 
61
61
  def public_dir_for type, options={}
62
62
  ::File.join(public_dirpath(options), type.to_s.pluralize)
63
- end
63
+ end
64
64
  end
65
-
65
+
66
66
  include Methods
67
67
  extend Methods
68
-
69
- end # Directories
68
+
69
+ end # Directories
70
70
  end
@@ -1,5 +1,5 @@
1
1
  module RailsAssist::Directory
2
- module App
2
+ module App
3
3
  module Methods
4
4
  def app_directories
5
5
  RailsAssist::Artifact::app_artifacts.map {|a| a.to_s.pluralize.to_sym}
@@ -14,8 +14,8 @@ module RailsAssist::Directory
14
14
  app_dirpath(options).dir
15
15
  end
16
16
  end
17
-
17
+
18
18
  include Methods
19
19
  extend Methods
20
20
  end
21
- end
21
+ end
@@ -1,15 +1,15 @@
1
- module RailsAssist::Directory
2
- module Container
1
+ module RailsAssist::Directory
2
+ module Container
3
3
 
4
4
  # return list of symbols for all kinds of supported Rails 3 containers
5
5
  # (those that have a [container]_dir method)
6
-
7
- module Methods
6
+
7
+ module Methods
8
8
  def rails_containers
9
9
  app_methods = RailsAssist::Directory.instance_methods
10
10
  artifact_methods = RailsAssist::Artifact::Directory.instance_methods
11
11
  all_methods = app_methods + artifact_methods
12
-
12
+
13
13
  all_methods.grep(/_dir$/).map{|dir| dir.to_s.gsub(/^(.*)_dir/, '\1').to_sym }
14
14
  end
15
15
 
@@ -17,7 +17,7 @@ module RailsAssist::Directory
17
17
  rails_containers.include?(type)
18
18
  end
19
19
  end
20
-
20
+
21
21
  include Methods
22
22
  extend Methods
23
23
  end