simple_form_epic_editor 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b4c183688af9e5bf6e618e592b9a64aa8e59bd3
4
+ data.tar.gz: 7754ea2e7546d9676896a37a27d445ac2c4fa4a2
5
+ SHA512:
6
+ metadata.gz: 1d6062e93209efce2042fdaa47bb9787fcdbd8bd92652df870ec32de68939324f8a5fb0b9845194a1de578623800a4d8d9520f829162536cf30c9d7a79c0d642
7
+ data.tar.gz: 0afe8e12ec525ca184a0b8934a1fff92b5cec8b5e552d17d8dd2d08d58e991a704b47a65b3f60ccedef071967d199eac3bc0bb0515ca366c8fde3ea1089c66d8
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ source 'https://rails-assets.org'
3
+
4
+ # Specify your gem's dependencies in simple_form_epic_editor.gemspec
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Tomas Celizna
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,84 @@
1
+ # Simple Form Epic Editor
2
+
3
+ Integrates the markdown editor [Epic Editor](https://github.com/OscarGodson/EpicEditor) with Rails and [Simple Form](https://github.com/plataformatec/simple_form).
4
+
5
+ This gem adjusts the default theme of [Epic Editor](https://github.com/OscarGodson/EpicEditor) and places the toolbar above the editing field.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'simple_form_epic_editor'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install simple_form_epic_editor
20
+
21
+ To make it work you need to require the javascripts in `application.js`:
22
+
23
+ //= require simple_form_epic_editor
24
+
25
+ ## Usage
26
+
27
+ Use in forms:
28
+
29
+ = form.input :body, as: :epic_editor
30
+
31
+ ## Styling
32
+
33
+ Styling for the editor is separated into three files:
34
+
35
+ * base.css
36
+ * preview.css
37
+ * editor.css
38
+
39
+ The default styling can be overridden by adding your own version of any or all of the three files in `lib/assets/stylesheets/simple_form_epic_editor/default_theme/`
40
+
41
+ Alternatively you can configure the editor to use another [theme](#theme).
42
+
43
+ ## Configuration
44
+
45
+ ### Toolbar
46
+
47
+ You can change the default button texts in an initializer:
48
+
49
+ ```Ruby
50
+ # config/initializers/simple_form_epic_editor.rb
51
+
52
+ SimpleFormEpicEditor::EpicEditorInput.configure do |c|
53
+ c.commands = [
54
+ @commands = {
55
+ edit: 'Edit',
56
+ preview: 'Render'
57
+ }
58
+ ]
59
+ end
60
+ ```
61
+
62
+ ### Theme
63
+
64
+ In the initializer you can assign any or all of the three stylesheets a new path:
65
+
66
+ ```Ruby
67
+ # config/initializers/simple_form_epic_editor.rb
68
+
69
+ SimpleFormEpicEditor::EpicEditorInput.configure do |c|
70
+ c.theme = {
71
+ base: '/simple_form_epic_editor/your_theme_name/base.css',
72
+ preview: '/simple_form_epic_editor/your_theme_name/preview.css',
73
+ editor: '/simple_form_epic_editor/your_theme_name/editor.css'
74
+ }
75
+ end
76
+ ```
77
+
78
+ ## Contributing
79
+
80
+ 1. Fork it ( https://github.com/[my-github-username]/simple_form_epic_editor/fork )
81
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
82
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
83
+ 4. Push to the branch (`git push origin my-new-feature`)
84
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,2 @@
1
+ //= require epiceditor
2
+ //= require simple_form_epic_editor/simple_form_epic_editor
@@ -0,0 +1,87 @@
1
+ # https://github.com/jquery-boilerplate/jquery-boilerplate/
2
+ do ($ = jQuery, window, document) ->
3
+
4
+ pluginName = 'simple_form_epic_editor'
5
+ defaults =
6
+ debug: false
7
+
8
+ # ---------------------------------------------------------------------
9
+
10
+ class Plugin
11
+ constructor: (@element, options) ->
12
+ @settings = $.extend {}, defaults, options
13
+
14
+ @$element = $(@element)
15
+
16
+ @_defaults = defaults
17
+ @_name = pluginName
18
+
19
+ @init()
20
+
21
+ init: ->
22
+ console.log 'init' if @settings.debug
23
+
24
+ # ---------------------------------------------------------------------
25
+
26
+ e = new EpicEditor(
27
+ container: @get_editor_wrapper().get(0)
28
+ textarea: @get_editor_textarea().get(0)
29
+ basePath: '/assets'
30
+ theme: {
31
+ base: "<%= SimpleFormEpicEditor::EpicEditorInput.configuration.theme[:base] %>"
32
+ preview: "<%= SimpleFormEpicEditor::EpicEditorInput.configuration.theme[:preview] %>"
33
+ editor: "<%= SimpleFormEpicEditor::EpicEditorInput.configuration.theme[:editor] %>"
34
+ }
35
+ button: false
36
+ ).load()
37
+
38
+ # ---------------------------------------------------------------------
39
+
40
+ @get_toolbar_ul().children('li:first').addClass('active')
41
+
42
+ @get_toolbar_lis().on 'click', (event) ->
43
+ $li = $(event.currentTarget)
44
+ $li.siblings('li').removeClass('active')
45
+ $li.addClass('active')
46
+ e[$li.data('toggle')]()
47
+
48
+ # ---------------------------------------------------------------------
49
+
50
+ get_editor_wrapper: -> @$element.children('div.editor:first')
51
+ get_editor_toolbar: -> @$element.children('div.toolbar:first')
52
+ get_editor_textarea: -> @get_editor_wrapper().children('textarea:first')
53
+ get_toolbar_ul: -> @get_editor_toolbar().children('ul:first')
54
+ get_toolbar_lis: -> @get_toolbar_ul().children('li')
55
+
56
+ # ---------------------------------------------------------------------
57
+
58
+ # A really lightweight plugin wrapper around the constructor,
59
+ # preventing against multiple instantiations and allowing any
60
+ # public function (ie. a function whose name doesn't start
61
+ # with an underscore) to be called via the jQuery plugin,
62
+ # e.g. $(element).defaultPluginName('functionName', arg1, arg2)
63
+
64
+ $.fn[pluginName] = (options) ->
65
+ args = arguments
66
+ if options is `undefined` or typeof options is "object"
67
+ @each ->
68
+ $.data this, "plugin_" + pluginName, new Plugin(this, options) unless $.data(this, "plugin_" + pluginName)
69
+
70
+ else if typeof options is "string" and options[0] isnt "_" and options isnt "init"
71
+ returns = undefined
72
+ @each ->
73
+ instance = $.data(this, "plugin_" + pluginName)
74
+ returns = instance[options].apply(instance, Array::slice.call(args, 1)) if instance instanceof Plugin and typeof instance[options] is "function"
75
+ $.data this, "plugin_" + pluginName, null if options is "destroy"
76
+
77
+ (if returns isnt `undefined` then returns else this)
78
+
79
+ # =====================================================================
80
+
81
+ $ ->
82
+
83
+ $('div.epic_editor').simple_form_epic_editor()
84
+
85
+ # make sure the plugin is correctly rebound to new elements
86
+ $('body').on 'dom_update', (e) ->
87
+ $('div.epic_editor').simple_form_epic_editor()
@@ -0,0 +1,36 @@
1
+ div.input.epic_editor {
2
+ div.toolbar {
3
+ ul.commands {
4
+ display: inline-block;
5
+ margin: 0;
6
+ padding: 0;
7
+ list-style: none;
8
+ margin-bottom: 5px;
9
+ width: 100%;
10
+
11
+ li {
12
+ display: inline-block;
13
+
14
+ span {
15
+ padding: 4px 8px 6px;
16
+ cursor: pointer;
17
+ display: inline-block;
18
+ border: 1px solid transparent;
19
+ }
20
+
21
+ &.active {
22
+ span {
23
+ color: rgba(0,0,0,1);
24
+ border: 1px solid rgba(0,0,0,1);
25
+ border-bottom: transparent;
26
+ }
27
+ }
28
+ }
29
+ }
30
+ }
31
+
32
+ div.epiceditor {
33
+ border: 1px solid rgb(0,0,0);
34
+ overflow: hidden;
35
+ }
36
+ }
@@ -0,0 +1,19 @@
1
+ html {
2
+ padding: 0;
3
+ margin: 0;
4
+ width: 100%;
5
+ height: 100%;
6
+ }
7
+
8
+ iframe {
9
+ margin: 0;
10
+ padding: 0;
11
+ }
12
+
13
+ body {
14
+ box-sizing: border-box;
15
+ height: 100%;
16
+ margin: 0;
17
+ padding: 0;
18
+ width: 100%;
19
+ }
@@ -0,0 +1,9 @@
1
+ body {
2
+ font-family: 'Menlo', monospace;
3
+ margin: 0;
4
+ background: rgb(245, 245, 245);
5
+ color: rgb(0, 0, 0);
6
+ font-size: 14px;
7
+ line-height: 18px;
8
+ padding: 5px;
9
+ }
@@ -0,0 +1,9 @@
1
+ body {
2
+ font-family: Helvetica, Arial, sans-serif;
3
+ background: rgb(255, 255, 255);
4
+ color: rgb(0, 0, 0);
5
+ font-size: 14px;
6
+ line-height: 18px;
7
+ padding: 5px;
8
+ margin: 0;
9
+ }
@@ -0,0 +1,15 @@
1
+ require "simple_form"
2
+ require "simple_form_epic_editor/engine"
3
+ require "simple_form_epic_editor/configuration"
4
+ require "simple_form_epic_editor/simple_form_epic_editor"
5
+ require "simple_form_epic_editor/version"
6
+
7
+ require "rails-assets-epiceditor"
8
+
9
+ # ---------------------------------------------------------------------
10
+
11
+ module SimpleForm
12
+ class FormBuilder
13
+ map_type :epic_editor, to: SimpleFormEpicEditor::EpicEditorInput
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ module SimpleFormEpicEditor
2
+ class Configuration
3
+
4
+ attr_accessor :commands, :theme
5
+
6
+ # TODO: Make everything customizable!
7
+
8
+ def initialize
9
+ @commands = {
10
+ edit: 'Write',
11
+ preview: 'Preview'
12
+ }
13
+ @theme = {
14
+ base: '/simple_form_epic_editor/default_theme/base.css',
15
+ preview: '/simple_form_epic_editor/default_theme/preview.css',
16
+ editor: '/simple_form_epic_editor/default_theme/editor.css'
17
+ }
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ module SimpleFormEpicEditor
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,68 @@
1
+ module SimpleFormEpicEditor
2
+ class EpicEditorInput < SimpleForm::Inputs::Base
3
+
4
+ class << self
5
+
6
+ attr_accessor :configuration
7
+
8
+ def configure
9
+ @configuration ||= Configuration.new
10
+ yield @configuration
11
+ end
12
+
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ end
18
+
19
+ # =====================================================================
20
+
21
+ # @return [String]
22
+ def input
23
+ toolbar + editor
24
+ end
25
+
26
+ private # =============================================================
27
+
28
+ # Array of commands for text area toolbar, arranged into command groups.
29
+ # @return [Hash]
30
+ def command_list
31
+ options[:commands] || SimpleFormEpicEditor::EpicEditorInput.configuration.commands
32
+ end
33
+
34
+ def editor
35
+ template.content_tag :div, class: %w(editor) do
36
+ text_area
37
+ end
38
+ end
39
+
40
+ # @return [String]
41
+ def text_area
42
+ @builder.text_area(attribute_name, input_html_options).html_safe
43
+ end
44
+
45
+ # @return [String]
46
+ def toolbar
47
+ template.content_tag :div, class: 'toolbar' do
48
+ commands
49
+ end.html_safe
50
+ end
51
+
52
+ # @return [String]
53
+ def commands
54
+ template.content_tag :ul, class: 'commands' do
55
+ command_list.map do |c, t|
56
+ command(c, t)
57
+ end.flatten.join.html_safe
58
+ end
59
+ end
60
+
61
+ def command(c, t)
62
+ template.content_tag :li, class: c.to_s.underscore.downcase, :"data-toggle" => c.to_s do
63
+ template.content_tag :span, t.to_s
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleFormEpicEditor
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_form_epic_editor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_form_epic_editor"
8
+ spec.version = SimpleFormEpicEditor::VERSION
9
+ spec.authors = ["Tomas Celizna"]
10
+ spec.email = ["tomas.celizna@gmail.com"]
11
+ spec.summary = %q{Integrates the markdown editor EpicEditor with Rails and Simple Form.}
12
+ spec.description = %q{Integrates the markdown editor EpicEditor with Rails and Simple Form.}
13
+ spec.homepage = "https://github.com/tomasc/simple_form_wysihtml"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "simple_form", ">= 3.0.2"
22
+ spec.add_dependency "rails-assets-epiceditor", ">= 0.2.2"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_form_epic_editor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Celizna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simple_form
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails-assets-epiceditor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Integrates the markdown editor EpicEditor with Rails and Simple Form.
70
+ email:
71
+ - tomas.celizna@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - lib/assets/javascripts/simple_form_epic_editor.js
82
+ - lib/assets/javascripts/simple_form_epic_editor/simple_form_epic_editor.js.coffee.erb
83
+ - lib/assets/stylesheets/simple_form_epic_editor.css.scss
84
+ - lib/assets/stylesheets/simple_form_epic_editor/default_theme/base.css
85
+ - lib/assets/stylesheets/simple_form_epic_editor/default_theme/editor.css
86
+ - lib/assets/stylesheets/simple_form_epic_editor/default_theme/preview.css
87
+ - lib/simple_form_epic_editor.rb
88
+ - lib/simple_form_epic_editor/configuration.rb
89
+ - lib/simple_form_epic_editor/engine.rb
90
+ - lib/simple_form_epic_editor/simple_form_epic_editor.rb
91
+ - lib/simple_form_epic_editor/version.rb
92
+ - simple_form_epic_editor.gemspec
93
+ homepage: https://github.com/tomasc/simple_form_wysihtml
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.1.10
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Integrates the markdown editor EpicEditor with Rails and Simple Form.
117
+ test_files: []
118
+ has_rdoc: