forked from valiot/administrate-field-enum
-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 79c7871
Showing
7 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
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,33 @@ | ||
# Administrate::Field::Enum | ||
|
||
A plugin to show enum attributes in [Administrate]. | ||
|
||
This repository is the first field plugin extracted out of Administrate. | ||
Although its structure may change, | ||
it's designed to act as a template for other Administrate field plugins. | ||
|
||
## FAQs | ||
|
||
**Q: How should I name my gem?** | ||
|
||
A: Administrate field gems must be named according to the [Rubygems naming guidelines]. | ||
|
||
Essentially, name your gem after the field class that it defines. | ||
If there's a namespace in the class name, that gets translated to a dash (`-`) in the gem name. | ||
If the class name is CamelCased, that translates to an underscore (`_`) in the gem name. | ||
|
||
Since all administrate field gems are under the namespace `Administrate::Field`, | ||
every field gem name should start with the prefix `administrate-field-`. | ||
|
||
Here are some examples (these don't correspond to actual gems): | ||
|
||
| Gem Name | Field Name | | ||
|----------------------------|------------------------------| | ||
| `administrate-field-enum` | `Administrate::Field::Enum` | | ||
| `administrate-field-file_upload` | `Administrate::Field::FileUpload` | | ||
| `administrate-field-geocoding-region` | `Administrate::Field::Geocoding::Region` | | ||
| `administrate-field-geocoding-geo_json` | `Administrate::Field::Geocoding::GeoJson` | | ||
|
||
[Rubygems naming guidelines]: http://guides.rubygems.org/name-your-gem/ | ||
|
||
[Administrate]: https://github.com/thoughtbot/administrate |
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,21 @@ | ||
$:.push File.expand_path('../lib', __FILE__) | ||
|
||
require 'administrate/field/enum' | ||
|
||
Gem::Specification.new do |gem| | ||
gem.name = 'administrate-field-enum' | ||
gem.version = Administrate::Field::Enum::VERSION | ||
gem.authors = ['Balbina Santana'] | ||
gem.email = ['[email protected]'] | ||
gem.homepage = 'https://github.com/DisruptiveAngels/administrate_field_enum' | ||
gem.summary = 'Enum field plugin for Administrate' | ||
gem.description = gem.summary | ||
gem.license = 'MIT' | ||
|
||
gem.require_paths = ['lib'] | ||
gem.files = `git ls-files`.split('\n') | ||
gem.test_files = `git ls-files -- {test,spec,features}/*`.split('\n') | ||
|
||
gem.add_dependency 'administrate', '>= 0.2.0.rc1', '< 0.3.0' | ||
gem.add_dependency 'rails', '~> 4.2', '< 5.1' | ||
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,28 @@ | ||
<%# | ||
# Enum Form Partial | ||
This partial renders an input element for enum attributes. | ||
By default, the input is a select field for the enum attributes. | ||
## Local variables: | ||
- `f`: | ||
A Rails form generator, used to help create the appropriate input fields. | ||
- `field`: | ||
An instance of [Administrate::Field::Enum][1]. | ||
A wrapper around the enum attributes pulled from the model. | ||
%> | ||
|
||
<div class="field-unit__label"> | ||
<%= f.label field.attribute %> | ||
</div> | ||
<div class="field-unit__field"> | ||
<%= f.select( | ||
field.attribute, | ||
options_for_select( | ||
f.object.class.public_send(field.attribute.to_s.pluralize) | ||
.map { |k, v| [k.humanize, k] }, | ||
f.object.public_send(field.attribute.to_s)), | ||
include_blank: false) %> | ||
</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,17 @@ | ||
<%# | ||
# Enum Index Partial | ||
This partial renders an enum attribute | ||
to be displayed on a resource's index page. | ||
By default, the attribute is rendered as a text tag. | ||
## Local variables: | ||
- `field`: | ||
An instance of [Administrate::Field::Enum][1]. | ||
A wrapper around the enum attributes pulled from the model. | ||
%> | ||
|
||
<%= field.to_s %> |
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,17 @@ | ||
<%# | ||
# Enum Show Partial | ||
This partial renders an enum attribute, | ||
to be displayed on a resource's show page. | ||
By default, the attribute is rendered as a text tag. | ||
## Local variables: | ||
- `field`: | ||
An instance of [Administrate::Field::Enum][1]. | ||
A wrapper around the enum attributes pulled from the model. | ||
%> | ||
|
||
<%= field.to_s %> |
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,13 @@ | ||
require 'administrate/field/base' | ||
require 'rails' | ||
|
||
module Administrate | ||
module Field | ||
class Enum < Administrate::Field::Base | ||
VERSION = '0.0.1' | ||
|
||
class Engine < ::Rails::Engine | ||
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,14 @@ | ||
require 'administrate/field/enum' | ||
|
||
describe Administrate::Field::Enum do | ||
describe '#to_partial_path' do | ||
it 'returns a partial based on the page being rendered' do | ||
page = :show | ||
field = Administrate::Field::Enum.new(:status, 'status', page) | ||
|
||
path = field.to_partial_path | ||
|
||
expect(path).to eq('/fields/enum/#{page}') | ||
end | ||
end | ||
end |