mirror of
https://github.com/danbee/administrate-field-color
synced 2025-03-04 08:49:06 +00:00
Initial commit
This commit is contained in:
commit
d55463f474
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Administrate::Field::Color
|
||||||
|
|
||||||
|
A plugin to handle colors in [Administrate].
|
||||||
|
|
||||||
|
[Administrate]: https://github.com/thoughtbot/administrate
|
||||||
21
administrate-field-color.gemspec
Normal file
21
administrate-field-color.gemspec
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
$:.push File.expand_path("../lib", __FILE__)
|
||||||
|
|
||||||
|
require "administrate/field/color"
|
||||||
|
|
||||||
|
Gem::Specification.new do |gem|
|
||||||
|
gem.name = "administrate-field-color"
|
||||||
|
gem.version = Administrate::Field::Color::VERSION
|
||||||
|
gem.authors = ["Dan Barber"]
|
||||||
|
gem.email = ["hello@danbarber.me"]
|
||||||
|
gem.homepage = "https://github.com/danbee/administrate_field_color"
|
||||||
|
gem.summary = "Color 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"
|
||||||
|
end
|
||||||
6
app/views/fields/color/_form.html.erb
Normal file
6
app/views/fields/color/_form.html.erb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<div class="field-unit__label">
|
||||||
|
<%= f.label field.attribute %>
|
||||||
|
</div>
|
||||||
|
<div class="field-unit__field">
|
||||||
|
<%= f.color_field field.attribute, style: 'height: 2.35em; width: 5em;' %>
|
||||||
|
</div>
|
||||||
2
app/views/fields/color/_index.html.erb
Normal file
2
app/views/fields/color/_index.html.erb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<%= content_tag :div, nil,
|
||||||
|
style: "height: 1.5em; width: 1.5em; background-color: #{field.data}" %>
|
||||||
2
app/views/fields/color/_show.html.erb
Normal file
2
app/views/fields/color/_show.html.erb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<%= content_tag :span, field.data,
|
||||||
|
style: "color: white; padding: 0.2em 0.5em; background-color: #{field.data}" %>
|
||||||
13
lib/administrate/field/color.rb
Normal file
13
lib/administrate/field/color.rb
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
require "administrate/field/base"
|
||||||
|
require "rails"
|
||||||
|
|
||||||
|
module Administrate
|
||||||
|
module Field
|
||||||
|
class Color < Administrate::Field::Base
|
||||||
|
VERSION = "0.0.1"
|
||||||
|
|
||||||
|
class Engine < ::Rails::Engine
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
14
spec/lib/administrate/field/color_spec.rb
Normal file
14
spec/lib/administrate/field/color_spec.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
require "administrate/field/color"
|
||||||
|
|
||||||
|
describe Administrate::Field::Color do
|
||||||
|
describe "#to_partial_path" do
|
||||||
|
it "returns a partial based on the page being rendered" do
|
||||||
|
page = :show
|
||||||
|
field = Administrate::Field::Color.new(:color, "#ea4049", page)
|
||||||
|
|
||||||
|
path = field.to_partial_path
|
||||||
|
|
||||||
|
expect(path).to eq("/fields/color/#{page}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user