-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
010ea1c
commit f02785c
Showing
17 changed files
with
171 additions
and
10 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="attachments-listing"> | ||
<%= image_tag field.data %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<%# | ||
# Attached One Form Partial | ||
This partial renders an input element for a single attached attribute. | ||
By default, the input is a file field for the attached file. | ||
## Local variables: | ||
- `f`: | ||
A Rails form generator, used to help create the appropriate input fields. | ||
- `field`: | ||
An instance of [Administrate::Field::Attached::One][1]. | ||
A wrapper around the attachment pulled from the database. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Attached/One | ||
%> | ||
|
||
|
||
<div class="field-unit__label"> | ||
<%= f.label field.attribute %> | ||
</div> | ||
<div class="field-unit__field"> | ||
<%= f.file_field(field.attribute) %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<%# | ||
# Attached One Show Partial | ||
This partial renders an attachment attribute, | ||
to be displayed on a resource's show page. | ||
By default, the attribute is rendered as an attachment tag. | ||
## Local variables: | ||
- `field`: | ||
An instance of [Administrate::Field::Attached::One][1]. | ||
A wrapper around the attachment pulled from the database. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Attached::One | ||
%> | ||
|
||
<% if field.attached? %> | ||
<%= render partial: "fields/attached/one/attachment", locals: { field: field } %> | ||
<% else %> | ||
No attachment | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "administrate/field/base" | ||
|
||
module Administrate | ||
module Field | ||
module Attached | ||
class Many < Administrate::Field::Base | ||
delegate :attached?, to: :data, allow_nil: true | ||
|
||
def to_partial_path | ||
"fields/attached/many/#{page}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "administrate/field/base" | ||
|
||
module Administrate | ||
module Field | ||
module Attached | ||
class One < Administrate::Field::Base | ||
delegate :attached?, to: :data, allow_nil: true | ||
|
||
def to_partial_path | ||
"fields/attached/one/#{page}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "rails_helper" | ||
require "administrate/field/attached/one" | ||
|
||
describe "field/attached/one/_form", type: :view do | ||
it "renders a singular file field" do | ||
model = build(:product, hero_image: nil) | ||
field = instance_double( | ||
"Administrate::Field::Attached::One", | ||
attribute: :hero_image, | ||
data: nil | ||
) | ||
|
||
fields model: model do |f| | ||
concat render( | ||
partial: "fields/attached/one/form", | ||
locals: {field: field, f: f} | ||
) | ||
end | ||
|
||
expect(rendered).to have_field( | ||
"product[hero_image]", type: "file" | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require "rails_helper" | ||
require "administrate/field/attached/one" | ||
|
||
describe "fields/attached/one/_show", type: :view do | ||
it "renders a 'No attachment' when missing a value" do | ||
field = instance_double( | ||
"Administrate::Field::Attached::One", | ||
attached?: false | ||
) | ||
|
||
render(partial: "fields/attached/one/show", locals: {field: field}) | ||
|
||
expect(rendered).to have_text("No attachment") | ||
end | ||
|
||
it "renders a preview when attached" do | ||
model = build(:product, hero_image: file_fixture("image.png")) | ||
field = instance_double( | ||
"Administrate::Field::Attached::One", | ||
data: model.hero_image, | ||
attached?: true | ||
) | ||
|
||
render(partial: "fields/attached/one/show", locals: {field: field}) | ||
|
||
expect(rendered).to have_element("img", src: rails_blob_url(model.hero_image)) | ||
.and(have_no_text("No attachment")) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.