schofield 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/generators/schofield_form/schofield_form_generator.rb +2 -0
- data/generators/{form → schofield_form}/templates/view__form.html.haml +0 -0
- data/lib/{tasks → schofield/tasks}/schofield.rake +0 -0
- data/lib/schofield/tasks.rb +3 -0
- data/schofield.gemspec +5 -4
- metadata +5 -4
- data/generators/form/form_generator.rb +0 -120
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
File without changes
|
File without changes
|
data/schofield.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{schofield}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marc Tauber"]
|
@@ -23,8 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
"README.rdoc",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
|
-
"generators/form/form_generator.rb",
|
27
|
-
"generators/form/templates/view__form.html.haml",
|
28
26
|
"generators/schofield_controller/schofield_controller_generator.rb",
|
29
27
|
"generators/schofield_controller/templates/controller_spec.rb",
|
30
28
|
"generators/schofield_controller/templates/helper_spec.rb",
|
@@ -39,8 +37,11 @@ Gem::Specification.new do |s|
|
|
39
37
|
"generators/schofield_controller/templates/unnested/new.rb",
|
40
38
|
"generators/schofield_controller/templates/unnested/show.rb",
|
41
39
|
"generators/schofield_controller/templates/view_spec.rb",
|
40
|
+
"generators/schofield_form/schofield_form_generator.rb",
|
41
|
+
"generators/schofield_form/templates/view__form.html.haml",
|
42
42
|
"lib/schofield.rb",
|
43
|
-
"lib/tasks
|
43
|
+
"lib/schofield/tasks.rb",
|
44
|
+
"lib/schofield/tasks/schofield.rake",
|
44
45
|
"schofield.gemspec",
|
45
46
|
"spec/schofield_spec.rb",
|
46
47
|
"spec/spec.opts",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schofield
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Tauber
|
@@ -48,8 +48,6 @@ files:
|
|
48
48
|
- README.rdoc
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
|
-
- generators/form/form_generator.rb
|
52
|
-
- generators/form/templates/view__form.html.haml
|
53
51
|
- generators/schofield_controller/schofield_controller_generator.rb
|
54
52
|
- generators/schofield_controller/templates/controller_spec.rb
|
55
53
|
- generators/schofield_controller/templates/helper_spec.rb
|
@@ -64,8 +62,11 @@ files:
|
|
64
62
|
- generators/schofield_controller/templates/unnested/new.rb
|
65
63
|
- generators/schofield_controller/templates/unnested/show.rb
|
66
64
|
- generators/schofield_controller/templates/view_spec.rb
|
65
|
+
- generators/schofield_form/schofield_form_generator.rb
|
66
|
+
- generators/schofield_form/templates/view__form.html.haml
|
67
67
|
- lib/schofield.rb
|
68
|
-
- lib/tasks
|
68
|
+
- lib/schofield/tasks.rb
|
69
|
+
- lib/schofield/tasks/schofield.rake
|
69
70
|
- schofield.gemspec
|
70
71
|
- spec/schofield_spec.rb
|
71
72
|
- spec/spec.opts
|
@@ -1,120 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
# Get current OS - needed for clipboard functionality
|
3
|
-
case RUBY_PLATFORM
|
4
|
-
when /darwin/ then
|
5
|
-
CURRENT_OS = :osx
|
6
|
-
when /win32/
|
7
|
-
CURRENT_OS = :win
|
8
|
-
begin
|
9
|
-
require 'win32/clipboard'
|
10
|
-
rescue LoadError
|
11
|
-
# Do nothing
|
12
|
-
end
|
13
|
-
else
|
14
|
-
CURRENT_OS = :x
|
15
|
-
end
|
16
|
-
|
17
|
-
class FormGenerator < Rails::Generator::NamedBase
|
18
|
-
|
19
|
-
default_options :haml => false,
|
20
|
-
:partial => false
|
21
|
-
|
22
|
-
VIEWS_PATH = File.join('app', 'views').freeze
|
23
|
-
IGNORED_COLUMNS = [:updated_at, :created_at].freeze
|
24
|
-
|
25
|
-
attr_reader :controller_file_name,
|
26
|
-
:controller_class_path,
|
27
|
-
:controller_class_nesting,
|
28
|
-
:controller_class_nesting_depth,
|
29
|
-
:controller_class_name,
|
30
|
-
:template_type
|
31
|
-
|
32
|
-
def initialize(runtime_args, runtime_options = {})
|
33
|
-
super
|
34
|
-
base_name, @controller_class_path = extract_modules(@name.pluralize)
|
35
|
-
controller_class_name_without_nesting, @controller_file_name = inflect_names(base_name)
|
36
|
-
@template_type = options[:haml] ? :haml : :erb
|
37
|
-
end
|
38
|
-
|
39
|
-
def manifest
|
40
|
-
record do |m|
|
41
|
-
if options[:partial]
|
42
|
-
controller_and_view_path = options[:controller] || File.join(controller_class_path, controller_file_name)
|
43
|
-
# Ensure directory exists.
|
44
|
-
m.directory File.join(VIEWS_PATH, controller_and_view_path)
|
45
|
-
# Create a form partial for the model as "_form" in it's views path.
|
46
|
-
m.template "view__form.html.#{template_type}", File.join(VIEWS_PATH, controller_and_view_path, "_form.html.#{template_type}")
|
47
|
-
else
|
48
|
-
# Load template file, and render without saving to file
|
49
|
-
template = File.read(File.join(source_root, "view__form.html.#{template_type}"))
|
50
|
-
erb = ERB.new(template, nil, '-')
|
51
|
-
generated_code = erb.result(binding).strip rescue nil
|
52
|
-
|
53
|
-
# Print the result, and copy to clipboard
|
54
|
-
puts "# ---------------------------------------------------------"
|
55
|
-
puts "# GENERATED FORMTASTIC CODE"
|
56
|
-
puts "# ---------------------------------------------------------"
|
57
|
-
puts
|
58
|
-
puts generated_code || " Nothing could be generated - model exists?"
|
59
|
-
puts
|
60
|
-
puts "# ---------------------------------------------------------"
|
61
|
-
puts " Copied to clipboard - just paste it!" if save_to_clipboard(generated_code)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
protected
|
67
|
-
|
68
|
-
# Save to lipboard with multiple OS support.
|
69
|
-
def save_to_clipboard(data)
|
70
|
-
return unless data
|
71
|
-
begin
|
72
|
-
case CURRENT_OS
|
73
|
-
when :osx
|
74
|
-
`echo "#{data}" | pbcopy`
|
75
|
-
when :win
|
76
|
-
::Win32::Clipboard.data = data
|
77
|
-
else # :linux/:unix
|
78
|
-
`echo "#{data}" | xsel --clipboard` || `echo "#{data}" | xclip`
|
79
|
-
end
|
80
|
-
rescue
|
81
|
-
false
|
82
|
-
else
|
83
|
-
true
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# Add additional model attributes if specified in args - probably not that common scenario.
|
88
|
-
def attributes
|
89
|
-
# Get columns for the requested model.
|
90
|
-
existing_attributes = @class_name.constantize.content_columns.reject { |column| IGNORED_COLUMNS.include?(column.name.to_sym) }
|
91
|
-
@args = super + existing_attributes
|
92
|
-
end
|
93
|
-
|
94
|
-
def add_options!(opt)
|
95
|
-
opt.separator ''
|
96
|
-
opt.separator 'Options:'
|
97
|
-
|
98
|
-
# Allow option to generate HAML views instead of ERB.
|
99
|
-
opt.on('--haml',
|
100
|
-
"Generate HAML output instead of the default ERB.") do |v|
|
101
|
-
options[:haml] = v
|
102
|
-
end
|
103
|
-
|
104
|
-
# Allow option to generate to partial in model's views path, instead of printing out in terminal.
|
105
|
-
opt.on('--partial',
|
106
|
-
"Save generated output directly to a form partial (app/views/{resource}/_form.html.*).") do |v|
|
107
|
-
options[:partial] = v
|
108
|
-
end
|
109
|
-
|
110
|
-
opt.on('--controller CONTROLLER_PATH',
|
111
|
-
"Specify a non-standard controller for the specified model (e.g. admin/posts).") do |v|
|
112
|
-
options[:controller] = v if v.present?
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def banner
|
117
|
-
"Usage: #{$0} form ExistingModelName [--haml] [--partial]"
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|