templet_rails 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +1059 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/templet/controller/USAGE +13 -0
- data/lib/generators/templet/controller/controller_generator.rb +106 -0
- data/lib/generators/templet/core/USAGE +23 -0
- data/lib/generators/templet/core/core_generator.rb +128 -0
- data/lib/generators/templet/core_rspec/USAGE +16 -0
- data/lib/generators/templet/core_rspec/core_rspec_generator.rb +65 -0
- data/lib/generators/templet/destroy/USAGE +19 -0
- data/lib/generators/templet/destroy/destroy_generator.rb +126 -0
- data/lib/generators/templet/routes/USAGE +14 -0
- data/lib/generators/templet/routes/routes_generator.rb +64 -0
- data/lib/generators/templet/rspec/USAGE +10 -0
- data/lib/generators/templet/rspec/rspec_generator.rb +124 -0
- data/lib/generators/templet/scaffold/USAGE +22 -0
- data/lib/generators/templet/scaffold/scaffold_generator.rb +75 -0
- data/lib/generators/templet/shared/actions_option.rb +24 -0
- data/lib/generators/templet/shared/add_routes_option.rb +19 -0
- data/lib/generators/templet/shared/child_option.rb +23 -0
- data/lib/generators/templet/shared/comment_tests_option.rb +19 -0
- data/lib/generators/templet/shared/core_helpers.rb +48 -0
- data/lib/generators/templet/shared/grand_parent_option.rb +20 -0
- data/lib/generators/templet/shared/model_fields.rb +55 -0
- data/lib/generators/templet/shared/model_option.rb +25 -0
- data/lib/generators/templet/shared/parent_option.rb +20 -0
- data/lib/generators/templet/templates/controller.rb.erb +108 -0
- data/lib/generators/templet/templates/core/app/base_viewer.rb +7 -0
- data/lib/generators/templet/templates/core/app/link_sets/navbar.rb +12 -0
- data/lib/generators/templet/templates/core/app/panel/flash_messages.rb +33 -0
- data/lib/generators/templet/templates/core/app/panel/layout_base.rb +40 -0
- data/lib/generators/templet/templates/core/app/panel/layout_header.rb +22 -0
- data/lib/generators/templet/templates/core/app/panel/layout_header_sidebar.rb +18 -0
- data/lib/generators/templet/templates/core/app/panel/nav.rb +55 -0
- data/lib/generators/templet/templates/core/app/panel/nav_args_option.rb +30 -0
- data/lib/generators/templet/templates/core/app/panel/options_config.rb +19 -0
- data/lib/generators/templet/templates/core/app/panel/show_parents_option.rb +22 -0
- data/lib/generators/templet/templates/core/app/panel/sidebar_links_option.rb +24 -0
- data/lib/generators/templet/templates/core/controllers/.keep +0 -0
- data/lib/generators/templet/templates/core/controllers/json_rendering_helpers.rb +12 -0
- data/lib/generators/templet/templates/core/controllers/rendering_helpers.rb +53 -0
- data/lib/generators/templet/templates/core/controllers/viewer_call_string.rb +144 -0
- data/lib/generators/templet/templates/core/controllers/viewer_call_string_class.rb +65 -0
- data/lib/generators/templet/templates/core/controllers/viewer_responders.rb +121 -0
- data/lib/generators/templet/templates/core/helpers/app.rb +4 -0
- data/lib/generators/templet/templates/core/helpers/templet_helper.rb +10 -0
- data/lib/generators/templet/templates/core/spec/support/apis/api_helper.rb +13 -0
- data/lib/generators/templet/templates/core/spec/support/apis/shared_examples_a_json_controller.rb +196 -0
- data/lib/generators/templet/templates/core/spec/support/core/model_parent_helpers.rb +36 -0
- data/lib/generators/templet/templates/core/spec/support/core/rest_link_procs_assignments.rb +43 -0
- data/lib/generators/templet/templates/core/spec/support/core/rest_link_procs_helpers.rb +15 -0
- data/lib/generators/templet/templates/core/spec/support/viewer/partial_test_helpers.rb +32 -0
- data/lib/generators/templet/templates/core/spec/support/viewer/shared_examples_a_viewer.rb +105 -0
- data/lib/generators/templet/templates/core/spec/templet/forms/bs_form_errors_spec.rb +18 -0
- data/lib/generators/templet/templates/core/spec/templet/forms/bs_form_spec.rb +58 -0
- data/lib/generators/templet/templates/core/spec/templet/layout/html_rails_spec.rb +64 -0
- data/lib/generators/templet/templates/core/spec/templet/links/bs_link_set_collection_spec.rb +79 -0
- data/lib/generators/templet/templates/core/spec/templet/links/rest_link_procs_params_spec.rb +68 -0
- data/lib/generators/templet/templates/core/spec/templet/links/rest_link_procs_parents_spec.rb +78 -0
- data/lib/generators/templet/templates/core/spec/templet/links/rest_link_procs_spec.rb +140 -0
- data/lib/generators/templet/templates/core/templet/constants.rb +54 -0
- data/lib/generators/templet/templates/core/templet/forms/bs_form.rb +73 -0
- data/lib/generators/templet/templates/core/templet/forms/bs_form_errors.rb +38 -0
- data/lib/generators/templet/templates/core/templet/forms/bs_form_field.rb +114 -0
- data/lib/generators/templet/templates/core/templet/forms/bs_form_group.rb +115 -0
- data/lib/generators/templet/templates/core/templet/layouts/html_rails.rb +36 -0
- data/lib/generators/templet/templates/core/templet/links.rb +28 -0
- data/lib/generators/templet/templates/core/templet/links/bs_btn_class.rb +61 -0
- data/lib/generators/templet/templates/core/templet/links/bs_link_set_base.rb +168 -0
- data/lib/generators/templet/templates/core/templet/links/bs_link_set_collection.rb +21 -0
- data/lib/generators/templet/templates/core/templet/links/bs_link_set_navigation.rb +62 -0
- data/lib/generators/templet/templates/core/templet/links/rest_link_procs.rb +163 -0
- data/lib/generators/templet/templates/core/templet/links/rest_link_procs_parent.rb +39 -0
- data/lib/generators/templet/templates/core/templet/links/rest_link_procs_sets.rb +30 -0
- data/lib/generators/templet/templates/core/templet/links/rest_link_text.rb +102 -0
- data/lib/generators/templet/templates/core/templet/links/rest_path.rb +90 -0
- data/lib/generators/templet/templates/core/templet/mixins.rb +9 -0
- data/lib/generators/templet/templates/core/templet/mixins/bs.rb +11 -0
- data/lib/generators/templet/templates/core/templet/mixins/bs/grid.rb +53 -0
- data/lib/generators/templet/templates/core/templet/mixins/bs/lists.rb +77 -0
- data/lib/generators/templet/templates/core/templet/mixins/field_procs.rb +140 -0
- data/lib/generators/templet/templates/core/templet/mixins/html_presenters.rb +82 -0
- data/lib/generators/templet/templates/core/templet/require_all.rb +45 -0
- data/lib/generators/templet/templates/core/templet/utils/html_search_form.rb +53 -0
- data/lib/generators/templet/templates/core/templet/utils/link_set_factory.rb +46 -0
- data/lib/generators/templet/templates/core/templet/utils/link_set_factory_wrapper.rb +53 -0
- data/lib/generators/templet/templates/core/templet/utils/list_model_parents.rb +27 -0
- data/lib/generators/templet/templates/core/templet/utils/navbar_form.rb +26 -0
- data/lib/generators/templet/templates/core/templet/utils/selected_wrapper.rb +40 -0
- data/lib/generators/templet/templates/core/templet/viewer.rb +11 -0
- data/lib/generators/templet/templates/core/templet/viewer/meta_model.rb +66 -0
- data/lib/generators/templet/templates/core/templet/viewer/meta_model_defaults.rb +56 -0
- data/lib/generators/templet/templates/core/templet/viewer/presenters.rb +44 -0
- data/lib/generators/templet/templates/core/templet/viewer/rest_actions.rb +24 -0
- data/lib/generators/templet/templates/core/templet/viewer_base.rb +111 -0
- data/lib/generators/templet/templates/core/templet/viewer_rest.rb +144 -0
- data/lib/generators/templet/viewer/USAGE +10 -0
- data/lib/generators/templet/viewer/viewer_generator.rb +86 -0
- data/lib/templet_rails.rb +5 -0
- data/lib/templet_rails/version.rb +3 -0
- data/templet_rails.gemspec +36 -0
- metadata +178 -0
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "templet_rails"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Description:
|
2
|
+
Creates a REST controller that calls a Viewer class to render a view.
|
3
|
+
If the PARENT option is valued then it creates a nested controller
|
4
|
+
with the given PARENT as the (inner) model.
|
5
|
+
If the MODEL option is given then it becomes the model name in the controller
|
6
|
+
- otherwise the model's name is inferred from the controller's name.
|
7
|
+
Controllers can be namespaced - but the corresponding model won't be.
|
8
|
+
|
9
|
+
Example:
|
10
|
+
rails generate templet:controller admin/user --parent group --model person --grand-parent sector --actions index show new create destroy
|
11
|
+
|
12
|
+
This will create:
|
13
|
+
app/controllers/admin/users_controller.rb
|
@@ -0,0 +1,106 @@
|
|
1
|
+
|
2
|
+
require_relative '../shared/parent_option'
|
3
|
+
require_relative '../shared/grand_parent_option'
|
4
|
+
require_relative '../shared/model_option'
|
5
|
+
require_relative '../shared/actions_option'
|
6
|
+
require_relative '../shared/model_fields'
|
7
|
+
|
8
|
+
class Templet::ControllerGenerator < Rails::Generators::NamedBase
|
9
|
+
include Shared::ModelOption
|
10
|
+
include Shared::ParentOption
|
11
|
+
include Shared::GrandParentOption
|
12
|
+
include Shared::ActionsOption
|
13
|
+
|
14
|
+
include Shared::ModelFields
|
15
|
+
|
16
|
+
TEMPLATE_FILE = 'controller.rb.erb'
|
17
|
+
|
18
|
+
SET_MODEL_ACTIONS = %w(show edit update destroy)
|
19
|
+
|
20
|
+
source_root File.expand_path('.', __FILE__)
|
21
|
+
desc
|
22
|
+
|
23
|
+
source_root File.expand_path('../../templates', __FILE__)
|
24
|
+
|
25
|
+
def create_controller
|
26
|
+
template TEMPLATE_FILE, controller_path
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def include_action?(action)
|
32
|
+
if actions
|
33
|
+
actions.include? action.to_s
|
34
|
+
else
|
35
|
+
true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def before_action(name, only=nil, prefix: "\n ")
|
40
|
+
return unless name
|
41
|
+
|
42
|
+
suffix = only&.any? ? ', only: %i(' + only * ' ' + ')' : ''
|
43
|
+
|
44
|
+
"#{prefix}before_action :set_#{name}#{suffix}\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
def set_model?
|
48
|
+
not actions or set_model_actions.any?
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_model_actions
|
52
|
+
actions ? SET_MODEL_ACTIONS & actions : SET_MODEL_ACTIONS
|
53
|
+
end
|
54
|
+
|
55
|
+
def controller_path
|
56
|
+
File.join("app/controllers", "#{file_path.pluralize}_controller.rb")
|
57
|
+
end
|
58
|
+
|
59
|
+
def model_plural
|
60
|
+
model_name.pluralize
|
61
|
+
end
|
62
|
+
|
63
|
+
def model_class_name
|
64
|
+
model_name.classify
|
65
|
+
end
|
66
|
+
|
67
|
+
def receiver
|
68
|
+
parent ? "@#{parent}.#{model_plural}" : model_class_name
|
69
|
+
end
|
70
|
+
|
71
|
+
def redirect_path(use_instance=true)
|
72
|
+
if parent
|
73
|
+
params = ", id: @#{model_name}" if model_name? and use_instance
|
74
|
+
|
75
|
+
"[#{path_scope}@#{parent}, #{path_element use_instance}#{params}]"
|
76
|
+
else
|
77
|
+
"[#{path_scope}#{path_element false}]"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def path_scope
|
82
|
+
elements = file_path.split('/')[0..-2]
|
83
|
+
|
84
|
+
if elements.any?
|
85
|
+
(elements.size == 1 ? ":#{elements.first}" : "'/#{elements * "/"}'") + ', '
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def path_element(use_instance)
|
90
|
+
if use_instance
|
91
|
+
(model_name? ? ':' : '@') + singular_name
|
92
|
+
else
|
93
|
+
":#{plural_name}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def path_controller(prefix=nil)
|
98
|
+
parents = [ parent.pluralize, '1' ] if parent
|
99
|
+
|
100
|
+
[ *file_path.split('/')[0..-2], *parents, plural_name, *prefix ] * '/'
|
101
|
+
end
|
102
|
+
|
103
|
+
def to_option(key, name, prefix='')
|
104
|
+
name ? "#{prefix}#{key}: :#{name}" : ''
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Description:
|
2
|
+
Installs the complete framework source under new directory trees,
|
3
|
+
by default, the core code is copied under app/helpers/templet/,
|
4
|
+
but you can change this with the option, DEST.
|
5
|
+
If you install under a directory, like lib/ or vendor/, then you must
|
6
|
+
uncomment the 'require' statements in the file, templet/require_all.rb.
|
7
|
+
This generator also creates another directory tree, app/helpers/app/,
|
8
|
+
which is where your own (application) code should go.
|
9
|
+
Should you later decide to delete all of these files then the generator,
|
10
|
+
templet:destroy can be used. This destroy generator also provides
|
11
|
+
selective deletion.
|
12
|
+
|
13
|
+
Example:
|
14
|
+
rails generate templet:core --dest lib/
|
15
|
+
|
16
|
+
This will create:
|
17
|
+
app/controllers/templet/* # Helper modules for invoking the framework
|
18
|
+
app/helpers/templet/** # If dest is given, it replaces 'app/helpers'
|
19
|
+
app/helpers/templet_helper.rb # For framework settings
|
20
|
+
app/helpers/app.rb # For global settings in your own code
|
21
|
+
app/helpers/app/** # Your own (application) code
|
22
|
+
spec/support/apis/* # For testing JSON sent from the controller
|
23
|
+
spec/support/templet/* # For testing the HTML in the rendered views
|
@@ -0,0 +1,128 @@
|
|
1
|
+
|
2
|
+
require_relative '../shared/core_helpers'
|
3
|
+
|
4
|
+
class Templet::CoreGenerator < Rails::Generators::Base
|
5
|
+
include Shared::CoreHelpers
|
6
|
+
|
7
|
+
CONTROLLER_SUBDIR = 'controllers/'
|
8
|
+
APIS_SUBDIR = 'apis/'
|
9
|
+
|
10
|
+
source_root File.expand_path('./', __FILE__)
|
11
|
+
desc
|
12
|
+
|
13
|
+
DEST_DESC = 'The directory that the core code will be copied beneath'
|
14
|
+
class_option :dest, type: :string, aliases: "-d", default: '', desc: DEST_DESC
|
15
|
+
|
16
|
+
def ensure_uninstalled
|
17
|
+
if dir = already_installed_at
|
18
|
+
puts "Can't install while there are files present in #{dir}"
|
19
|
+
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_templet_core
|
25
|
+
create_templet_tree
|
26
|
+
|
27
|
+
create_controller_modules
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_app
|
31
|
+
create_app_tree
|
32
|
+
|
33
|
+
create_app_rb
|
34
|
+
create_templet_helper_rb
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_rspec_support
|
38
|
+
if rspec?
|
39
|
+
directory spec_support_dir_source, spec_support_dir_target
|
40
|
+
|
41
|
+
directory api_support_dir_source, api_support_dir_target
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def create_templet_tree
|
48
|
+
directory core_dir_source, core_dir_target
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_controller_modules
|
52
|
+
directory controller_dir_source, controller_dir_target
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_app_tree
|
56
|
+
directory app_dir_source, app_dir_target
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_app_rb
|
60
|
+
copy_helper 'app.rb'
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_templet_helper_rb
|
64
|
+
copy_helper 'templet_helper.rb'
|
65
|
+
end
|
66
|
+
|
67
|
+
def copy_helper(file)
|
68
|
+
copy_file helper_dir_source(file), helper_dir_target(file)
|
69
|
+
end
|
70
|
+
|
71
|
+
def core_dir_source
|
72
|
+
SOURCE_ROOT + TEMPLET_SUBDIR
|
73
|
+
end
|
74
|
+
def core_dir_target
|
75
|
+
core_dest_subdir + TEMPLET_SUBDIR
|
76
|
+
end
|
77
|
+
|
78
|
+
def controller_dir_source
|
79
|
+
SOURCE_ROOT + CONTROLLER_SUBDIR
|
80
|
+
end
|
81
|
+
def controller_dir_target
|
82
|
+
APP_ROOT + CONTROLLER_SUBDIR + TEMPLET_SUBDIR
|
83
|
+
end
|
84
|
+
|
85
|
+
def app_dir_source
|
86
|
+
SOURCE_ROOT + APP_SUBDIR
|
87
|
+
end
|
88
|
+
def app_dir_target
|
89
|
+
APP_ROOT + HELPERS_SUBDIR + APP_SUBDIR
|
90
|
+
end
|
91
|
+
|
92
|
+
def helper_dir_source(file)
|
93
|
+
SOURCE_ROOT + HELPERS_SUBDIR + file
|
94
|
+
end
|
95
|
+
def helper_dir_target(file)
|
96
|
+
APP_ROOT + HELPERS_SUBDIR + file
|
97
|
+
end
|
98
|
+
|
99
|
+
def spec_support_dir_source
|
100
|
+
SOURCE_ROOT + spec_support_dir + 'viewer/'
|
101
|
+
end
|
102
|
+
def spec_support_dir_target
|
103
|
+
spec_support_dir + TEMPLET_SUBDIR
|
104
|
+
end
|
105
|
+
|
106
|
+
def api_support_dir_source
|
107
|
+
SOURCE_ROOT + spec_support_dir + APIS_SUBDIR
|
108
|
+
end
|
109
|
+
def api_support_dir_target
|
110
|
+
spec_support_dir + APIS_SUBDIR
|
111
|
+
end
|
112
|
+
|
113
|
+
def dest_dirs
|
114
|
+
super + [ LIB_ROOT + TEMPLET_SUBDIR, core_dest_subdir + TEMPLET_SUBDIR ]
|
115
|
+
end
|
116
|
+
|
117
|
+
def core_dest_subdir
|
118
|
+
if ( dest = options['dest'] ).present?
|
119
|
+
if Dir.exists? dest
|
120
|
+
dest + (dest.end_with?('/') ? '' : '/')
|
121
|
+
else
|
122
|
+
raise "Destination directory, #{dest}, must exist"
|
123
|
+
end
|
124
|
+
else
|
125
|
+
APP_ROOT + HELPERS_SUBDIR
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Description:
|
2
|
+
Generates Rspec tests for two sections of the core code.
|
3
|
+
First, tests to check the HTML in the view layouts.
|
4
|
+
Second, an optional step that adds various tests for the framework itself.
|
5
|
+
This second step is superfluous unless you're going to change the source
|
6
|
+
code - as these tests offer few, if any, real safeguards.
|
7
|
+
Note that the framework tests (second step) will only be installed if
|
8
|
+
the option, --include-core-specs is given, and also if the core is kept
|
9
|
+
in its default directory, i.e. under app/helpers/templet/.
|
10
|
+
|
11
|
+
Example:
|
12
|
+
rails generate template:core_rspec --include-core-specs
|
13
|
+
|
14
|
+
This will create files under the directories:
|
15
|
+
spec/helpers/app/panel/ # For testing layouts
|
16
|
+
spec/helpers/templet/ # If --include-core-specs is given
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
require_relative '../shared/core_helpers'
|
3
|
+
|
4
|
+
class Templet::CoreRspecGenerator < Rails::Generators::Base
|
5
|
+
include Shared::CoreHelpers
|
6
|
+
|
7
|
+
PANEL_SUBDIR = 'panel/'
|
8
|
+
|
9
|
+
DESC = "Add specs for the templet core (default: false)"
|
10
|
+
class_option 'include-core-specs', type: :boolean, default: false, desc: DESC
|
11
|
+
|
12
|
+
source_root File.expand_path('./', __FILE__)
|
13
|
+
desc
|
14
|
+
|
15
|
+
def copy_app_panel_specs
|
16
|
+
directory app_panel_dir_source, app_panel_dir_target
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_templet_specs
|
20
|
+
if include_core_specs? and Dir.exists? core_default_dir
|
21
|
+
directory spec_support_dir_source, spec_support_dir_target
|
22
|
+
|
23
|
+
directory spec_templet_dir_source, spec_templet_dir_target
|
24
|
+
|
25
|
+
puts message_for_file_change
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def app_panel_dir_source
|
32
|
+
SOURCE_ROOT + SPEC_SUBDIR + PANEL_SUBDIR
|
33
|
+
end
|
34
|
+
def app_panel_dir_target
|
35
|
+
SPEC_SUBDIR + HELPERS_SUBDIR + APP_SUBDIR + PANEL_SUBDIR
|
36
|
+
end
|
37
|
+
|
38
|
+
def spec_templet_dir_source
|
39
|
+
SOURCE_ROOT + SPEC_SUBDIR + TEMPLET_SUBDIR
|
40
|
+
end
|
41
|
+
|
42
|
+
def spec_templet_dir_target
|
43
|
+
SPEC_SUBDIR + HELPERS_SUBDIR + TEMPLET_SUBDIR
|
44
|
+
end
|
45
|
+
|
46
|
+
def spec_support_dir_source
|
47
|
+
SOURCE_ROOT + spec_support_dir + 'core/'
|
48
|
+
end
|
49
|
+
def spec_support_dir_target
|
50
|
+
spec_support_dir + TEMPLET_SUBDIR
|
51
|
+
end
|
52
|
+
|
53
|
+
def include_core_specs?
|
54
|
+
options['include-core-specs']
|
55
|
+
end
|
56
|
+
|
57
|
+
def message_for_file_change
|
58
|
+
%Q(
|
59
|
+
If you get rspec failures you may need to change values in the file:
|
60
|
+
spec/support/templet/model_parent_helpers.rb
|
61
|
+
Or if you'd rather just get rid of these failing tests run this:
|
62
|
+
$ rails generate templet:destroy --rm-core-rspec
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Description:
|
2
|
+
Entirely removes the framework and nearly all of the generated code.
|
3
|
+
(It doesn't delete the generated controllers - you must do this yourself.)
|
4
|
+
The option, --pretend (-p) will show what files will be deleted,
|
5
|
+
without carrying out the actual erasure.
|
6
|
+
For safety, if it's called without any options it'll delete nothing.
|
7
|
+
|
8
|
+
Examples:
|
9
|
+
# To get rid of the whole lot
|
10
|
+
rails generate templet:destroy -all
|
11
|
+
|
12
|
+
# To delete just the templet core tests - leaves everything else intact
|
13
|
+
rails generate templet:destroy --only-core-rspec
|
14
|
+
|
15
|
+
# To remove just the framework - perhaps before applying a future update!
|
16
|
+
rails generate templet:destroy --rm-core
|
17
|
+
|
18
|
+
# To get rid of all the application's viewer files
|
19
|
+
rails generate templet:destroy --rm-app
|
@@ -0,0 +1,126 @@
|
|
1
|
+
|
2
|
+
class Templet::DestroyGenerator < Rails::Generators::Base
|
3
|
+
ALL_DESC = "Remove all files to do with this framework (default: false)"
|
4
|
+
class_option 'all', type: :boolean, default: false, desc: ALL_DESC
|
5
|
+
|
6
|
+
CORE_DESC = "Remove all of the core (framework) files (default: false)"
|
7
|
+
class_option 'rm-core', type: :boolean, default: false, desc: CORE_DESC
|
8
|
+
|
9
|
+
APP_DESC = "Remove the application files under app/helpers/app/ and all tests (default: false)"
|
10
|
+
class_option 'rm-app', type: :boolean, default: false, desc: APP_DESC
|
11
|
+
|
12
|
+
SPEC_DESC = "Remove just the tests for the template core (default: false)"
|
13
|
+
class_option 'rm-core-rspec', type: :boolean, default: false, desc: SPEC_DESC
|
14
|
+
|
15
|
+
DEST_DESC = 'The directory that the core code will be copied into'
|
16
|
+
class_option :dest, type: :string, aliases: "-d", default: '', desc: DEST_DESC
|
17
|
+
|
18
|
+
source_root File.expand_path('.', __FILE__)
|
19
|
+
desc
|
20
|
+
|
21
|
+
def check
|
22
|
+
if rm_all? or rm_core_rspec? or rm_app? or rm_core?
|
23
|
+
unless yes? 'Please confirm that you are about to delete a slew of files?'
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
else
|
27
|
+
generate 'templet:destroy --help'
|
28
|
+
|
29
|
+
puts 'Note that at least one option needs to be given'
|
30
|
+
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def rm_core
|
36
|
+
if core_delete?
|
37
|
+
rm %w(app/helpers/templet/ lib/templet/)
|
38
|
+
|
39
|
+
if ( dest = options['dest'] ).present?
|
40
|
+
rm dest
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def rm_controller
|
46
|
+
if core_delete?
|
47
|
+
rm %w(app/controllers/templet/)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def rm_helpers_rb
|
52
|
+
if core_delete?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def rm_app_trees
|
57
|
+
if app_delete?
|
58
|
+
rm %w(app/helpers/app.rb app/helpers/templet_helper.rb)
|
59
|
+
|
60
|
+
rm 'app/helpers/app/'
|
61
|
+
|
62
|
+
rm %w(spec/helpers/app/ spec/support/templet/)
|
63
|
+
|
64
|
+
rm %w(spec/apis/ spec/support/apis/)
|
65
|
+
|
66
|
+
puts "Note that any generated controllers won't have been removed"
|
67
|
+
puts " You'll have to manually delete these yourself"
|
68
|
+
puts " There may also be entries in config/routes.rb"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def rm_core_rspec
|
73
|
+
if rm_all? or rm_core? or rm_core_rspec?
|
74
|
+
rm %w(spec/helpers/templet/)
|
75
|
+
|
76
|
+
rm %w(spec/support/templet/rest_link_procs_assignments.rb
|
77
|
+
spec/support/templet/rest_link_procs_helpers.rb
|
78
|
+
spec/support/templet/model_parent_helpers.rb)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def rm(*paths)
|
85
|
+
paths.flatten.compact.each do |path|
|
86
|
+
#puts " #{exists?(path) ? '*' : '?'} #{path}"
|
87
|
+
|
88
|
+
remove_file path if exists?(path)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def exists?(path)
|
93
|
+
if not path or path.empty?
|
94
|
+
false
|
95
|
+
elsif path.include?('.') or path =~ /[A-Z]/ or not path.end_with?('/')
|
96
|
+
File.exists? path
|
97
|
+
else
|
98
|
+
Dir.exists? path
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def core_delete?
|
103
|
+
rm_all? or (rm_core? and not rm_core_rspec?)
|
104
|
+
end
|
105
|
+
|
106
|
+
def app_delete?
|
107
|
+
rm_all? or (rm_app? and not rm_core_rspec?)
|
108
|
+
end
|
109
|
+
|
110
|
+
def rm_core_rspec?
|
111
|
+
options['rm-core-rspec']
|
112
|
+
end
|
113
|
+
|
114
|
+
def rm_app?
|
115
|
+
options['rm-app']
|
116
|
+
end
|
117
|
+
|
118
|
+
def rm_core?
|
119
|
+
options['rm-core']
|
120
|
+
end
|
121
|
+
|
122
|
+
def rm_all?
|
123
|
+
options['all']
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|