mirror of
https://github.com/danbee/administrate-field-markdown
synced 2025-03-04 08:39:06 +00:00
Initial commit
This commit is contained in:
commit
6eea8ca810
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
|
||||
22
administrate-field-markdown.gemspec
Normal file
22
administrate-field-markdown.gemspec
Normal file
@ -0,0 +1,22 @@
|
||||
$:.push File.expand_path("../lib", __FILE__)
|
||||
|
||||
require "administrate/field/markdown"
|
||||
|
||||
Gem::Specification.new do |gem|
|
||||
gem.name = "administrate-field-markdown"
|
||||
gem.version = Administrate::Field::Markdown::VERSION
|
||||
gem.authors = ["Dan Barber"]
|
||||
gem.email = ["hello@danbarber.me"]
|
||||
gem.homepage = "https://github.com/danbee/administrate_field_markdown"
|
||||
gem.summary = "Markdown 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"
|
||||
gem.add_dependency "kramdown", "~> 1.10"
|
||||
end
|
||||
6
app/views/fields/markdown/_form.html.erb
Normal file
6
app/views/fields/markdown/_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.text_area field.attribute %>
|
||||
</div>
|
||||
1
app/views/fields/markdown/_index.html.erb
Normal file
1
app/views/fields/markdown/_index.html.erb
Normal file
@ -0,0 +1 @@
|
||||
<%= field.truncate %>
|
||||
1
app/views/fields/markdown/_show.html.erb
Normal file
1
app/views/fields/markdown/_show.html.erb
Normal file
@ -0,0 +1 @@
|
||||
<%= field.rendered.html_safe %>
|
||||
28
lib/administrate/field/markdown.rb
Normal file
28
lib/administrate/field/markdown.rb
Normal file
@ -0,0 +1,28 @@
|
||||
require "administrate/field/base"
|
||||
require "rails"
|
||||
require "kramdown"
|
||||
|
||||
module Administrate
|
||||
module Field
|
||||
class Markdown < Administrate::Field::Base
|
||||
VERSION = "0.0.1"
|
||||
|
||||
class Engine < ::Rails::Engine
|
||||
end
|
||||
|
||||
def rendered
|
||||
Kramdown::Document.new(data).to_html
|
||||
end
|
||||
|
||||
def truncate
|
||||
data.to_s[0...truncation_length]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def truncation_length
|
||||
options.fetch(:truncate, 50)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
spec/lib/administrate/field/markdown_spec.rb
Normal file
25
spec/lib/administrate/field/markdown_spec.rb
Normal file
@ -0,0 +1,25 @@
|
||||
require "administrate/field/markdown"
|
||||
|
||||
describe Administrate::Field::Markdown do
|
||||
describe "#rendered" do
|
||||
it "renders markdown to HTML" do
|
||||
markdown = "This is some markdown to render"
|
||||
|
||||
page = :show
|
||||
field = Administrate::Field::Markdown.new(:markdown, markdown, page)
|
||||
|
||||
expect(field.rendered).to eq("<p>This is some markdown to render</p>\n")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#to_partial_path" do
|
||||
it "returns a partial based on the page being rendered" do
|
||||
page = :show
|
||||
field = Administrate::Field::Markdown.new(:markdown, "", page)
|
||||
|
||||
path = field.to_partial_path
|
||||
|
||||
expect(path).to eq("/fields/markdown/#{page}")
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user