-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Field generators #992
Field generators #992
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,22 +14,36 @@ def self.template_source_path | |
source_root template_source_path | ||
|
||
def copy_partials | ||
copy_field_partial(:index) | ||
copy_field_partial(:show) | ||
copy_field_partial(:form) | ||
resource_path = args.first.try(:underscore) | ||
|
||
if resource_path == 'all' | ||
field_types = Dir.entries(self.class.template_source_path).reject{ |name| name[0] == "."} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space missing to the left of {. |
||
|
||
field_types.each do |field_type| | ||
copy_field_partials(field_type) | ||
end | ||
else | ||
copy_field_partials(resource_path) | ||
end | ||
end | ||
|
||
private | ||
|
||
def copy_field_partial(partial_name) | ||
resource_path = args.first.try(:underscore) | ||
def copy_field_partials(resource_path) | ||
copy_field_partial(resource_path, :index) | ||
copy_field_partial(resource_path, :show) | ||
copy_field_partial(resource_path, :form) | ||
end | ||
|
||
def copy_field_partial(resource_path, partial_name) | ||
template_file = "#{resource_path}/_#{partial_name}.html.erb" | ||
|
||
copy_file( | ||
template_file, | ||
"app/views/fields/#{template_file}", | ||
) | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at class body end. |
||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
require "spec_helper" | ||
require "rails_helper" | ||
require "generators/administrate/views/field_generator" | ||
require "support/generator_spec_helpers" | ||
|
||
describe Administrate::Generators::Views::FieldGenerator, :generator do | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at block body beginning. |
||
context "for an existing field type" do | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at block body beginning. |
||
describe "administrate:views:field field_name" do | ||
it "copies the `_show` partial into the app/views/fields directory" do | ||
expected_contents = contents_for_field_template(:string, :show) | ||
|
@@ -32,6 +34,46 @@ | |
expect(contents).to eq(expected_contents) | ||
end | ||
end | ||
|
||
describe "administrate:views:field all" do | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at block body beginning. |
||
let(:field_types) { Dir.entries("app/views/fields").reject{ |name| name[0] == "."} } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space missing to the left of {. |
||
|
||
it "copies the `_show` partial for each field type" do | ||
run_generator ["all"] | ||
|
||
field_types.each do |field_type| | ||
expected_contents = contents_for_field_template(field_type, :show) | ||
contents = File.read(file("app/views/fields/#{field_type}/_show.html.erb")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [85/80] |
||
|
||
expect(contents).to eq(expected_contents) | ||
end | ||
end | ||
|
||
it "copies the `_form` partial for each field type" do | ||
run_generator ["all"] | ||
|
||
field_types.each do |field_type| | ||
expected_contents = contents_for_field_template(field_type, :form) | ||
contents = File.read(file("app/views/fields/#{field_type}/_form.html.erb")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [85/80] |
||
|
||
expect(contents).to eq(expected_contents) | ||
end | ||
end | ||
|
||
it "copies the `_index` partial for each field type" do | ||
run_generator ["all"] | ||
|
||
field_types.each do |field_type| | ||
expected_contents = contents_for_field_template(field_type, :index) | ||
contents = File.read(file("app/views/fields/#{field_type}/_index.html.erb")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [86/80] |
||
|
||
expect(contents).to eq(expected_contents) | ||
end | ||
end | ||
|
||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at block body end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at block body end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at block body end. |
||
end | ||
|
||
def contents_for_field_template(field_name, partial_name) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.