├── .ruby-version
├── Gemfile
├── .gitignore
├── lib
└── administrate
│ └── field
│ └── image.rb
├── .github
└── workflows
│ └── main.yml
├── Rakefile
├── spec
└── lib
│ └── administrate
│ └── field
│ └── image_spec.rb
├── app
└── views
│ └── fields
│ └── image
│ ├── _index.html.erb
│ ├── _show.html.erb
│ └── _form.html.erb
├── administrate-field-image.gemspec
├── CHANGELOG.md
├── LICENSE
└── README.md
/.ruby-version:
--------------------------------------------------------------------------------
1 | ruby-3.0.2
2 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source "https://rubygems.org"
2 |
3 | gemspec
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.bundle/
2 | /.yardoc
3 | /Gemfile.lock
4 | /_yardoc/
5 | /coverage/
6 | /doc/
7 | /pkg/
8 | /spec/reports/
9 | /tmp/
10 |
--------------------------------------------------------------------------------
/lib/administrate/field/image.rb:
--------------------------------------------------------------------------------
1 | require "administrate/field/base"
2 | require "rails"
3 |
4 | module Administrate
5 | module Field
6 | class Image < Administrate::Field::Base
7 | class Engine < ::Rails::Engine
8 | end
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: CI
3 | on: [push]
4 |
5 | jobs:
6 | test:
7 | runs-on: ubuntu-latest
8 |
9 | steps:
10 | - uses: actions/checkout@v2
11 | - name: Set up Ruby
12 | uses: ruby/setup-ruby@v1
13 | - name: Install dependencies
14 | run: bundle install
15 | - name: Run tests
16 | run: bundle exec rspec
17 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env rake
2 |
3 | begin
4 | require "bundler/setup"
5 | rescue LoadError
6 | puts "You must `gem install bundler` and `bundle install` to run rake tasks"
7 | end
8 |
9 | require "bundler/gem_tasks"
10 |
11 | ##
12 | # Configure the test suite.
13 | ##
14 | require "rspec/core"
15 | require "rspec/core/rake_task"
16 |
17 | RSpec::Core::RakeTask.new
18 |
19 | ##
20 | # By default, just run the tests.
21 | ##
22 | task default: :spec
23 |
--------------------------------------------------------------------------------
/spec/lib/administrate/field/image_spec.rb:
--------------------------------------------------------------------------------
1 | require "administrate/field/image"
2 |
3 | describe Administrate::Field::Image do
4 | describe "#to_partial_path" do
5 | it "returns a partial based on the page being rendered" do
6 | page = :show
7 | field = Administrate::Field::Image.new(:image, "/a.jpg", page)
8 |
9 | path = field.to_partial_path
10 |
11 | expect(path).to eq("/fields/image/#{page}")
12 | end
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/app/views/fields/image/_index.html.erb:
--------------------------------------------------------------------------------
1 | <%#
2 | # Image Index Partial
3 |
4 | This partial renders an image attribute
5 | to be displayed on a resource's index page.
6 |
7 | By default, the attribute is rendered as an image tag.
8 |
9 | ## Local variables:
10 |
11 | - `field`:
12 | An instance of [Administrate::Field::Image][1].
13 | A wrapper around the image url pulled from the database.
14 |
15 | [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image
16 | %>
17 |
18 | <%= image_tag field.data if field.data.present? %>
19 |
--------------------------------------------------------------------------------
/app/views/fields/image/_show.html.erb:
--------------------------------------------------------------------------------
1 | <%#
2 | # Image Show Partial
3 |
4 | This partial renders an image attribute,
5 | to be displayed on a resource's show page.
6 |
7 | By default, the attribute is rendered as an image tag.
8 |
9 | ## Local variables:
10 |
11 | - `field`:
12 | An instance of [Administrate::Field::Image][1].
13 | A wrapper around the image url pulled from the database.
14 |
15 | [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image
16 | %>
17 |
18 | <%= image_tag field.data if field.data.present? %>
19 |
--------------------------------------------------------------------------------
/app/views/fields/image/_form.html.erb:
--------------------------------------------------------------------------------
1 | <%#
2 | # Image Form Partial
3 |
4 | This partial renders an input element for image attributes.
5 | By default, the input is a text field for the image's URL.
6 |
7 | ## Local variables:
8 |
9 | - `f`:
10 | A Rails form generator, used to help create the appropriate input fields.
11 | - `field`:
12 | An instance of [Administrate::Field::Image][1].
13 | A wrapper around the image url pulled from the database.
14 |
15 | [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image
16 | %>
17 |
18 |
19 | <%= f.label field.attribute %>
20 |
21 |
22 | <%= f.file_field field.attribute %>
23 |
24 |
--------------------------------------------------------------------------------
/administrate-field-image.gemspec:
--------------------------------------------------------------------------------
1 | $:.push File.expand_path("../lib", __FILE__)
2 |
3 | Gem::Specification.new do |gem|
4 | gem.name = "administrate-field-image"
5 | gem.version = "1.2.0"
6 | gem.authors = ["Grayson Wright", "Nick Charlton"]
7 | gem.email = ["wright.grayson@gmail.com", "nick@nickcharlton.net"]
8 | gem.homepage = "https://github.com/graysonwright/administrate-field-image"
9 | gem.summary = "Official Image field plugin for Administrate"
10 | gem.description = gem.summary
11 | gem.license = "MIT"
12 |
13 | gem.require_paths = ["lib"]
14 | gem.files = `git ls-files`.split("\n")
15 | gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16 |
17 | gem.add_dependency "administrate", ">= 0.2.0.rc1"
18 |
19 | gem.add_development_dependency "rspec", "~> 3.4"
20 | end
21 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # CHANGELOG
2 |
3 | ## 1.2.0 (2022-07-11)
4 |
5 | * Fix #index preview crash on when no image attached ([#23])
6 | * Use file_field instead of text_field in the form ([#22]]
7 | * Setup GitHub Actions for CI ([#21])
8 |
9 | [#21]: https://github.com/thoughtbot/administrate-field-image/pull/21
10 | [#22]: https://github.com/thoughtbot/administrate-field-image/pull/22
11 | [#23]: https://github.com/thoughtbot/administrate-field-image/pull/23
12 |
13 | ## 1.1.0 (2017-03-24)
14 |
15 | * Don't crash if image is nil/blank ([#9][])
16 | * Remove Explicit Dependency on Rails ([#11][])
17 | * Adds this CHANGELOG ([#12][])
18 |
19 | [#9]: https://github.com/thoughtbot/administrate-field-image/pull/9
20 | [#11]: https://github.com/thoughtbot/administrate-field-image/pull/11
21 | [#12]: https://github.com/thoughtbot/administrate-field-image/pull/12
22 |
23 | ## 1.0.0 (2017-01-16)
24 |
25 | * Extraction from [administrate][].
26 | * Rails 5 support.
27 |
28 | [administrate]: https://github.com/thoughtbot/administrate
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright (c) 2008-2017 thoughtbot, inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Administrate::Field::Image
2 |
3 | A plugin to show image URLs in [Administrate].
4 |
5 | This repository is the first field plugin extracted out of Administrate.
6 | Although its structure may change,
7 | it's designed to act as a template for other Administrate field plugins.
8 |
9 | ## FAQs
10 |
11 | **Q: How should I name my gem?**
12 |
13 | A: Administrate field gems must be named according to the [Rubygems naming guidelines].
14 |
15 | Essentially, name your gem after the field class that it defines.
16 | If there's a namespace in the class name, that gets translated to a dash (`-`) in the gem name.
17 | If the class name is CamelCased, that translates to an underscore (`_`) in the gem name.
18 |
19 | Since all administrate field gems are under the namespace `Administrate::Field`,
20 | every field gem name should start with the prefix `administrate-field-`.
21 |
22 | Here are some examples (these don't correspond to actual gems):
23 |
24 | | Gem Name | Field Name |
25 | |----------------------------|------------------------------|
26 | | `administrate-field-image` | `Administrate::Field::Image` |
27 | | `administrate-field-file_upload` | `Administrate::Field::FileUpload` |
28 | | `administrate-field-geocoding-region` | `Administrate::Field::Geocoding::Region` |
29 | | `administrate-field-geocoding-geo_json` | `Administrate::Field::Geocoding::GeoJson` |
30 |
31 | [Rubygems naming guidelines]: http://guides.rubygems.org/name-your-gem/
32 |
33 | [Administrate]: https://github.com/thoughtbot/administrate
34 |
--------------------------------------------------------------------------------