From 12843ef2a04f6c1ad2c386cb512c2baf2f185c8e Mon Sep 17 00:00:00 2001 From: Grayson Wright Date: Sat, 13 Feb 2016 22:24:51 -0800 Subject: [PATCH] Extract image field into a separate gem Feature: **When I** have a custom field type that I want to share with others, **I want to** reference an official template for a field gem **so I can** more easily package my field for sharing. Implementation: Create a template for field plugins by extracting the image field into its own gem. This is a breaking change with an easy fix - anybody who uses Image fields will need to add `gem "administrate-field-image"` to their `Gemfile`. The source for the image field gem is up at https://github.com/graysonwright/administrate-field-image. --- CHANGELOG.md | 7 +++++++ Gemfile | 1 + Gemfile.lock | 8 ++++++++ app/views/fields/image/_form.html.erb | 23 ----------------------- app/views/fields/image/_index.html.erb | 18 ------------------ app/views/fields/image/_show.html.erb | 18 ------------------ docs/customizing_dashboards.md | 1 - lib/administrate/field/image.rb | 8 -------- spec/lib/fields/image_spec.rb | 14 -------------- 9 files changed, 16 insertions(+), 82 deletions(-) delete mode 100644 app/views/fields/image/_form.html.erb delete mode 100644 app/views/fields/image/_index.html.erb delete mode 100644 app/views/fields/image/_show.html.erb delete mode 100644 lib/administrate/field/image.rb delete mode 100644 spec/lib/fields/image_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 18065e6918..897ea3dfd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,13 @@ ### Upcoming Release +* [#476] [CHANGE] Extract `Administrate::Field::Image` into its own gem. + Users who have image fields in their dashboards + should add to their `Gemfile`: + ```ruby + gem "administrate-field-image" + ``` + ### 0.1.5 (April 1, 2016) * [master] [BUGFIX] Protect from CSRF attacks [CVE-2016-3098] diff --git a/Gemfile b/Gemfile index 400a47d620..3136c4e359 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ ruby "2.2.3" gemspec +gem "administrate-field-image", path: "../administrate-field-image" gem "delayed_job_active_record" gem "high_voltage" gem "markdown-rails" diff --git a/Gemfile.lock b/Gemfile.lock index 3e5c694dbc..5946522ff8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +PATH + remote: ../administrate-field-image + specs: + administrate-field-image (0.0.1) + administrate (~> 0.1.3) + rails (~> 4.2) + PATH remote: . specs: @@ -280,6 +287,7 @@ PLATFORMS DEPENDENCIES administrate! + administrate-field-image! ammeter appraisal awesome_print diff --git a/app/views/fields/image/_form.html.erb b/app/views/fields/image/_form.html.erb deleted file mode 100644 index 18712a711a..0000000000 --- a/app/views/fields/image/_form.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -<%# -# Image Form Partial - -This partial renders an input element for image attributes. -By default, the input is a text field for the image's URL. - -## Local variables: - -- `f`: - A Rails form generator, used to help create the appropriate input fields. -- `field`: - An instance of [Administrate::Field::Image][1]. - A wrapper around the image url pulled from the database. - -[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image -%> - -
- <%= f.label field.attribute %> -
-
- <%= f.text_field field.attribute %> -
diff --git a/app/views/fields/image/_index.html.erb b/app/views/fields/image/_index.html.erb deleted file mode 100644 index a02b714c70..0000000000 --- a/app/views/fields/image/_index.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -<%# -# Image Index Partial - -This partial renders an image attribute -to be displayed on a resource's index page. - -By default, the attribute is rendered as an image tag. - -## Local variables: - -- `field`: - An instance of [Administrate::Field::Image][1]. - A wrapper around the image url pulled from the database. - -[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image -%> - -<%= image_tag field.data %> diff --git a/app/views/fields/image/_show.html.erb b/app/views/fields/image/_show.html.erb deleted file mode 100644 index 52a7892389..0000000000 --- a/app/views/fields/image/_show.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -<%# -# Image Show Partial - -This partial renders an image attribute, -to be displayed on a resource's show page. - -By default, the attribute is rendered as an image tag. - -## Local variables: - -- `field`: - An instance of [Administrate::Field::Image][1]. - A wrapper around the image url pulled from the database. - -[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image -%> - -<%= image_tag field.data %> diff --git a/docs/customizing_dashboards.md b/docs/customizing_dashboards.md index 7f48367482..c0e9c9bd0d 100644 --- a/docs/customizing_dashboards.md +++ b/docs/customizing_dashboards.md @@ -57,7 +57,6 @@ specify, including: - `Field::Email` - `Field::HasMany` - `Field::HasOne` -- `Field::Image` - `Field::Number` - `Field::Polymorphic` - `Field::Select` diff --git a/lib/administrate/field/image.rb b/lib/administrate/field/image.rb deleted file mode 100644 index 3589634926..0000000000 --- a/lib/administrate/field/image.rb +++ /dev/null @@ -1,8 +0,0 @@ -require_relative "base" - -module Administrate - module Field - class Image < Field::Base - end - end -end diff --git a/spec/lib/fields/image_spec.rb b/spec/lib/fields/image_spec.rb deleted file mode 100644 index 52b79e39d6..0000000000 --- a/spec/lib/fields/image_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require "administrate/field/image" - -describe Administrate::Field::Image do - describe "#to_partial_path" do - it "returns a partial based on the page being rendered" do - page = :show - field = Administrate::Field::Image.new(:image, "/a.jpg", page) - - path = field.to_partial_path - - expect(path).to eq("/fields/image/#{page}") - end - end -end