Skip to content

Commit

Permalink
Add support for generators in mountable engines
Browse files Browse the repository at this point in the history
  • Loading branch information
aldesantis committed Jan 15, 2018
1 parent 0744117 commit d6c8f28
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Implemented support for using the generators in mountable engines

### Fixed

- Fixed edge cases in collection rendering for resources without a decorator
Expand Down
17 changes: 10 additions & 7 deletions lib/generators/pragma/resource_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,33 @@ def copy_initializer_file
private

def copy_resource_files
directory 'resource/resource', "app/resources/api/v#{options['version']}/#{file_name}"
directory(
'resource/resource',
"app/resources/#{namespaced_path}/api/v#{options['version']}/#{file_name}"
)
end

def copy_controller
template(
'resource/controller.rb',
"app/controllers/api/v#{options['version']}/#{file_name.pluralize}_controller.rb"
"app/controllers/#{namespaced_path}/api/v#{options['version']}/#{file_name.pluralize}_controller.rb"
)
end

def copy_spec
template(
'resource/spec.rb',
"spec/requests/api/v#{options['version']}/#{file_name.pluralize}_spec.rb"
"spec/requests/#{namespaced_path}/api/v#{options['version']}/#{file_name.pluralize}_spec.rb"
)
end

def class_path
def route_path
['api', "v#{options['version']}"]
end

# Taken from https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb
def generate_route
class_path.each_with_index do |namespace, index|
route_path.each_with_index do |namespace, index|
write("namespace :#{namespace} do", index + 1)
end

Expand All @@ -54,7 +57,7 @@ def generate_route
)
# rubocop:enable Metrics/LineLength

class_path.each_index do |index|
route_path.each_index do |index|
write('end', route_length - index)
end

Expand All @@ -73,7 +76,7 @@ def write(str, indent)
end

def route_length
class_path.length
route_path.length
end
end
end
2 changes: 2 additions & 0 deletions lib/generators/pragma/templates/resource/controller.rb.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
class <%= file_name.pluralize.camelcase %>Controller < ResourceController
end
end
end
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
module <%= file_name.camelcase %>
Expand All @@ -8,3 +9,4 @@ module API
end
end
end
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
module <%= file_name.camelcase %>
Expand All @@ -8,3 +9,4 @@ module API
end
end
end
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
module <%= file_name.camelcase %>
Expand All @@ -8,3 +9,4 @@ module API
end
end
end
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
module <%= file_name.camelcase %>
Expand All @@ -13,3 +14,4 @@ module API
end
end
end
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
module <%= file_name.camelcase %>
Expand All @@ -9,3 +10,4 @@ module API
end
end
end
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
module <%= file_name.camelcase %>
Expand All @@ -8,3 +9,4 @@ module API
end
end
end
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
module <%= file_name.camelcase %>
Expand All @@ -8,3 +9,4 @@ module API
end
end
end
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
module <%= file_name.camelcase %>
Expand All @@ -8,3 +9,4 @@ module API
end
end
end
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
module <%= file_name.camelcase %>
Expand All @@ -8,3 +9,4 @@ module API
end
end
end
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
module <%= file_name.camelcase %>
Expand All @@ -8,3 +9,4 @@ module API
end
end
end
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% module_namespacing do -%>
module API
module V<%= options['version'] %>
module <%= file_name.camelcase %>
Expand Down Expand Up @@ -27,3 +28,4 @@ module API
end
end
end
<% end -%>
2 changes: 1 addition & 1 deletion lib/pragma/rails/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Pragma
module Rails
VERSION = '2.0.1'
VERSION = '2.1.0'
end
end

0 comments on commit d6c8f28

Please sign in to comment.