view_mapper 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -2
- data/VERSION +1 -1
- data/generators/scaffold_for_view/scaffold_for_view_generator.rb +2 -6
- data/generators/view_for/view_for_generator.rb +1 -5
- data/lib/view_mapper/{has_many_view.rb → has_many_child_models.rb} +33 -37
- data/lib/view_mapper/model_info.rb +8 -0
- data/lib/view_mapper/view_mapper.rb +15 -2
- data/lib/view_mapper/views/auto_complete/auto_complete_view.rb +77 -0
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/controller.rb +3 -1
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/layout.html.erb +0 -0
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/view_edit.html.erb +1 -1
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/view_new.html.erb +1 -1
- data/lib/view_mapper/views/has_many/has_many_view.rb +28 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/helper.rb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/layout.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/model.rb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/nested_attributes.js +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/style.css +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_child_form.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_edit.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_form.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_new.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_show.html.erb +0 -0
- data/lib/view_mapper/{paperclip_view.rb → views/paperclip/paperclip_view.rb} +6 -2
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/migration.rb +1 -1
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/model.rb +0 -0
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_edit.html.erb +0 -0
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_new.html.erb +0 -0
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_show.html.erb +0 -0
- data/lib/view_mapper.rb +4 -3
- data/test/{fake → generators/fake}/fake_generator.rb +0 -0
- data/test/generators/fake/templates/fake_template1.html.erb +1 -0
- data/test/generators/fake/templates/fake_template2.html.erb +1 -0
- data/test/{scaffold_for_view_generator_test.rb → generators/scaffold_for_view/scaffold_for_view_generator_test.rb} +2 -2
- data/test/{view_for_generator_test.rb → generators/view_for/view_for_generator_test.rb} +0 -0
- data/test/model_info_test.rb +12 -3
- data/test/test_helper.rb +12 -8
- data/test/view_mapper_test.rb +13 -2
- data/test/{auto_complete_test.rb → views/auto_complete/auto_complete_test.rb} +63 -40
- data/test/{expected_templates/auto_complete/index.html.erb → views/auto_complete/expected_templates/actual_index} +2 -0
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/edit.html.erb +7 -3
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/expected_routes.rb +0 -0
- data/test/{expected_templates/paperclip → views/auto_complete/expected_templates}/index.html.erb +3 -1
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/new.html.erb +7 -3
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/show.html.erb +6 -1
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/standard_routes.rb +0 -0
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/testies.html.erb +0 -0
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/testies_controller.rb +2 -1
- data/test/views/fake/fake_view.rb +7 -0
- data/test/views/fake/templates/fake_template1.html.erb +1 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/_form.html.erb +0 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/_person.html.erb +4 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/create_parents.rb +4 -3
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/edit.html.erb +0 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/index.html.erb +1 -1
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/new.html.erb +0 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/parent.rb +2 -1
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/show.html.erb +4 -0
- data/test/{has_many_view_test.rb → views/has_many/has_many_view_test.rb} +17 -17
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/create_testies.rb +4 -3
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/edit.html.erb +4 -0
- data/test/views/paperclip/expected_templates/index.html.erb +26 -0
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/new.html.erb +4 -0
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/show.html.erb +5 -0
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/testy.rb +0 -0
- data/test/{paperclip_view_test.rb → views/paperclip/paperclip_view_test.rb} +17 -9
- data/view_mapper.gemspec +77 -124
- metadata +72 -120
- data/lib/view_mapper/auto_complete_templates/functional_test.rb +0 -45
- data/lib/view_mapper/auto_complete_templates/helper.rb +0 -2
- data/lib/view_mapper/auto_complete_templates/helper_test.rb +0 -4
- data/lib/view_mapper/auto_complete_templates/style.css +0 -54
- data/lib/view_mapper/auto_complete_templates/view_index.html.erb +0 -24
- data/lib/view_mapper/auto_complete_templates/view_show.html.erb +0 -10
- data/lib/view_mapper/auto_complete_view.rb +0 -44
- data/lib/view_mapper/has_many_templates/controller.rb +0 -85
- data/lib/view_mapper/has_many_templates/fixtures.yml +0 -19
- data/lib/view_mapper/has_many_templates/functional_test.rb +0 -45
- data/lib/view_mapper/has_many_templates/helper_test.rb +0 -4
- data/lib/view_mapper/has_many_templates/migration.rb +0 -16
- data/lib/view_mapper/has_many_templates/unit_test.rb +0 -8
- data/lib/view_mapper/has_many_templates/view_index.html.erb +0 -24
- data/lib/view_mapper/paperclip_templates/controller.rb +0 -85
- data/lib/view_mapper/paperclip_templates/fixtures.yml +0 -19
- data/lib/view_mapper/paperclip_templates/functional_test.rb +0 -45
- data/lib/view_mapper/paperclip_templates/helper.rb +0 -2
- data/lib/view_mapper/paperclip_templates/helper_test.rb +0 -4
- data/lib/view_mapper/paperclip_templates/layout.html.erb +0 -17
- data/lib/view_mapper/paperclip_templates/style.css +0 -54
- data/lib/view_mapper/paperclip_templates/unit_test.rb +0 -8
- data/lib/view_mapper/paperclip_templates/view_index.html.erb +0 -24
- data/test/database.yml +0 -3
- data/test/fake_view.rb +0 -7
- data/test/rails_generator/base.rb +0 -266
- data/test/rails_generator/commands.rb +0 -621
- data/test/rails_generator/generated_attribute.rb +0 -46
- data/test/rails_generator/generators/components/model/model_generator.rb +0 -45
- data/test/rails_generator/generators/components/scaffold/scaffold_generator.rb +0 -102
- data/test/rails_generator/lookup.rb +0 -249
- data/test/rails_generator/manifest.rb +0 -53
- data/test/rails_generator/options.rb +0 -150
- data/test/rails_generator/scripts/destroy.rb +0 -29
- data/test/rails_generator/scripts/generate.rb +0 -7
- data/test/rails_generator/scripts/update.rb +0 -12
- data/test/rails_generator/scripts.rb +0 -89
- data/test/rails_generator/secret_key_generator.rb +0 -24
- data/test/rails_generator/simple_logger.rb +0 -46
- data/test/rails_generator/spec.rb +0 -44
@@ -1,89 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/options'
|
2
|
-
|
3
|
-
module Rails
|
4
|
-
module Generator
|
5
|
-
module Scripts
|
6
|
-
|
7
|
-
# Generator scripts handle command-line invocation. Each script
|
8
|
-
# responds to an invoke! class method which handles option parsing
|
9
|
-
# and generator invocation.
|
10
|
-
class Base
|
11
|
-
include Options
|
12
|
-
default_options :collision => :ask, :quiet => false
|
13
|
-
|
14
|
-
# Run the generator script. Takes an array of unparsed arguments
|
15
|
-
# and a hash of parsed arguments, takes the generator as an option
|
16
|
-
# or first remaining argument, and invokes the requested command.
|
17
|
-
def run(args = [], runtime_options = {})
|
18
|
-
begin
|
19
|
-
parse!(args.dup, runtime_options)
|
20
|
-
rescue OptionParser::InvalidOption => e
|
21
|
-
# Don't cry, script. Generators want what you think is invalid.
|
22
|
-
end
|
23
|
-
|
24
|
-
# Generator name is the only required option.
|
25
|
-
unless options[:generator]
|
26
|
-
usage if args.empty?
|
27
|
-
options[:generator] ||= args.shift
|
28
|
-
end
|
29
|
-
|
30
|
-
# Look up generator instance and invoke command on it.
|
31
|
-
Rails::Generator::Base.instance(options[:generator], args, options).command(options[:command]).invoke!
|
32
|
-
rescue => e
|
33
|
-
puts e
|
34
|
-
puts " #{e.backtrace.join("\n ")}\n" if options[:backtrace]
|
35
|
-
raise SystemExit
|
36
|
-
end
|
37
|
-
|
38
|
-
protected
|
39
|
-
# Override with your own script usage banner.
|
40
|
-
def banner
|
41
|
-
"Usage: #{$0} generator [options] [args]"
|
42
|
-
end
|
43
|
-
|
44
|
-
def usage_message
|
45
|
-
usage = "\nInstalled Generators\n"
|
46
|
-
Rails::Generator::Base.sources.inject([]) do |mem, source|
|
47
|
-
# Using an association list instead of a hash to preserve order,
|
48
|
-
# for aesthetic reasons more than anything else.
|
49
|
-
label = source.label.to_s.capitalize
|
50
|
-
pair = mem.assoc(label)
|
51
|
-
mem << (pair = [label, []]) if pair.nil?
|
52
|
-
pair[1] |= source.names
|
53
|
-
mem
|
54
|
-
end.each do |label, names|
|
55
|
-
usage << " #{label}: #{names.join(', ')}\n" unless names.empty?
|
56
|
-
end
|
57
|
-
|
58
|
-
usage << <<end_blurb
|
59
|
-
|
60
|
-
More are available at http://wiki.rubyonrails.org/rails/pages/AvailableGenerators
|
61
|
-
1. Download, for example, login_generator.zip
|
62
|
-
2. Unzip to directory #{Dir.user_home}/.rails/generators/login
|
63
|
-
to use the generator with all your Rails apps
|
64
|
-
end_blurb
|
65
|
-
|
66
|
-
if Object.const_defined?(:RAILS_ROOT)
|
67
|
-
usage << <<end_blurb
|
68
|
-
or to #{File.expand_path(RAILS_ROOT)}/lib/generators/login
|
69
|
-
to use with this app only.
|
70
|
-
end_blurb
|
71
|
-
end
|
72
|
-
|
73
|
-
usage << <<end_blurb
|
74
|
-
3. Run generate with no arguments for usage information
|
75
|
-
#{$0} login
|
76
|
-
|
77
|
-
Generator gems are also available:
|
78
|
-
1. gem search -r generator
|
79
|
-
2. gem install login_generator
|
80
|
-
3. #{$0} login
|
81
|
-
|
82
|
-
end_blurb
|
83
|
-
return usage
|
84
|
-
end
|
85
|
-
end # Base
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'active_support/deprecation'
|
2
|
-
|
3
|
-
module Rails
|
4
|
-
# A class for creating random secret keys. This class will do its best to create a
|
5
|
-
# random secret key that's as secure as possible, using whatever methods are
|
6
|
-
# available on the current platform. For example:
|
7
|
-
#
|
8
|
-
# generator = Rails::SecretKeyGenerator("some unique identifier, such as the application name")
|
9
|
-
# generator.generate_secret # => "f3f1be90053fa851... (some long string)"
|
10
|
-
#
|
11
|
-
# This class is *deprecated* in Rails 2.2 in favor of ActiveSupport::SecureRandom.
|
12
|
-
# It is currently a wrapper around ActiveSupport::SecureRandom.
|
13
|
-
class SecretKeyGenerator
|
14
|
-
def initialize(identifier)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Generate a random secret key with the best possible method available on
|
18
|
-
# the current platform.
|
19
|
-
def generate_secret
|
20
|
-
ActiveSupport::SecureRandom.hex(64)
|
21
|
-
end
|
22
|
-
deprecate :generate_secret=>"You should use ActiveSupport::SecureRandom.hex(64)"
|
23
|
-
end
|
24
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Rails
|
2
|
-
module Generator
|
3
|
-
class SimpleLogger # :nodoc:
|
4
|
-
attr_reader :out
|
5
|
-
attr_accessor :quiet
|
6
|
-
|
7
|
-
def initialize(out = $stdout)
|
8
|
-
@out = out
|
9
|
-
@quiet = false
|
10
|
-
@level = 0
|
11
|
-
end
|
12
|
-
|
13
|
-
def log(status, message, &block)
|
14
|
-
@out.print("%12s %s%s\n" % [status, ' ' * @level, message]) unless quiet
|
15
|
-
indent(&block) if block_given?
|
16
|
-
end
|
17
|
-
|
18
|
-
def indent(&block)
|
19
|
-
@level += 1
|
20
|
-
if block_given?
|
21
|
-
begin
|
22
|
-
block.call
|
23
|
-
ensure
|
24
|
-
outdent
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def outdent
|
30
|
-
@level -= 1
|
31
|
-
if block_given?
|
32
|
-
begin
|
33
|
-
block.call
|
34
|
-
ensure
|
35
|
-
indent
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
def method_missing(method, *args, &block)
|
42
|
-
log(method.to_s, args.first, &block)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Rails
|
2
|
-
module Generator
|
3
|
-
# A spec knows where a generator was found and how to instantiate it.
|
4
|
-
# Metadata include the generator's name, its base path, and the source
|
5
|
-
# which yielded it (PathSource, GemPathSource, etc.)
|
6
|
-
class Spec
|
7
|
-
attr_reader :name, :path, :source
|
8
|
-
|
9
|
-
def initialize(name, path, source)
|
10
|
-
@name, @path, @source = name, path, source
|
11
|
-
end
|
12
|
-
|
13
|
-
# Look up the generator class. Require its class file, find the class
|
14
|
-
# in ObjectSpace, tag it with this spec, and return.
|
15
|
-
def klass
|
16
|
-
unless @klass
|
17
|
-
require class_file
|
18
|
-
@klass = lookup_class
|
19
|
-
@klass.spec = self
|
20
|
-
end
|
21
|
-
@klass
|
22
|
-
end
|
23
|
-
|
24
|
-
def class_file
|
25
|
-
"#{path}/#{name}_generator.rb"
|
26
|
-
end
|
27
|
-
|
28
|
-
def class_name
|
29
|
-
"#{name.camelize}Generator"
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
# Search for the first Class descending from Rails::Generator::Base
|
34
|
-
# whose name matches the requested class name.
|
35
|
-
def lookup_class
|
36
|
-
ObjectSpace.each_object(Class) do |obj|
|
37
|
-
return obj if obj.ancestors.include?(Rails::Generator::Base) and
|
38
|
-
obj.name.split('::').last == class_name
|
39
|
-
end
|
40
|
-
raise NameError, "Missing #{class_name} class in #{class_file}"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|