-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Showing
6 changed files
with
111 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
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,8 @@ | ||
:ruby | ||
js_data = { | ||
js_location: field.js_location, | ||
css_location: field.css_location, | ||
instance_config: field.instance_config | ||
} | ||
|
||
= form.text_area field.method_name, field.html_attributes.reverse_merge(data: { richtext: 'simplemde', options: js_data.to_json }).reverse_merge({ value: field.form_value }) |
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
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 @@ | ||
require 'rails_admin/config/fields/base' | ||
|
||
module RailsAdmin | ||
module Config | ||
module Fields | ||
module Types | ||
class SimpleMDE < RailsAdmin::Config::Fields::Types::Text | ||
# Register field type for the type loader | ||
RailsAdmin::Config::Fields::Types.register(self) | ||
|
||
# If you want to have a different SimpleMDE config for each instance | ||
# you can override this option with these values: https://github.com/sparksuite/simplemde-markdown-editor#configuration | ||
register_instance_option :instance_config do | ||
nil | ||
end | ||
|
||
# Use this if you want to point to a cloud instance of the base SimpleMDE | ||
register_instance_option :js_location do | ||
"#{Rails.application.config.assets.prefix}/simplemde.min.js" | ||
end | ||
|
||
register_instance_option :css_location do | ||
"#{Rails.application.config.assets.prefix}/simplemde.min.css" | ||
end | ||
|
||
register_instance_option :partial do | ||
:form_simple_mde | ||
end | ||
end | ||
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
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,32 @@ | ||
require 'spec_helper' | ||
|
||
describe RailsAdmin::Config::Fields::Types::SimpleMDE do | ||
describe 'asset locations' do | ||
before do | ||
@custom_prefix = '/foo' | ||
@default_prefix = Rails.application.config.assets.prefix | ||
Rails.application.config.assets.prefix = @custom_prefix | ||
RailsAdmin.config FieldTest do | ||
field :text_field, :simple_mde | ||
end | ||
end | ||
|
||
after do | ||
Rails.application.config.assets.prefix = @default_prefix | ||
end | ||
|
||
it 'allows custom assets prefix for js' do | ||
expect( | ||
RailsAdmin.config(FieldTest).fields.detect { |f| f.name == :text_field }.with(object: FieldTest.new).js_location[0..(@custom_prefix.length - 1)], | ||
).to eq @custom_prefix | ||
end | ||
|
||
it 'allows custom assets prefix for css' do | ||
expect( | ||
RailsAdmin.config(FieldTest).fields.detect { |f| f.name == :text_field }.with(object: FieldTest.new).css_location[0..(@custom_prefix.length - 1)], | ||
).to eq @custom_prefix | ||
end | ||
end | ||
|
||
it_behaves_like 'a generic field type', :text_field, :simple_mde | ||
end |