bootstrap_md_editor 0.1.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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +36 -0
- data/app/assets/javascripts/bootstrap_md_editor.coffee +123 -0
- data/app/controllers/editor_controller.rb +7 -0
- data/app/helpers/bootstrap_md_editor/view_helpers.rb +7 -0
- data/app/views/bootstrap_md_editor/_editor.html.erb +12 -0
- data/app/views/bootstrap_md_editor/_preview.html.erb +4 -0
- data/app/views/bootstrap_md_editor/_text_area.html.erb +5 -0
- data/app/views/bootstrap_md_editor/_toolbar.html.erb +51 -0
- data/config/routes.rb +3 -0
- data/lib/bootstrap_md_editor.rb +6 -0
- data/lib/bootstrap_md_editor/engine.rb +5 -0
- data/lib/bootstrap_md_editor/railtie.rb +7 -0
- data/lib/bootstrap_md_editor/version.rb +3 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e116fc797a462bdf122a3538ac5a9987fd1336be
|
4
|
+
data.tar.gz: b2945b3c536ea69c48347c469e96fee2cd86a17b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 42826e4453696850a19c510436e0f5916642d87aae29ab7bdefa1c40a0e8bf12db259fac76df1ec1169813f067feab9d5ce515d363f2b8bf3b49950340332293
|
7
|
+
data.tar.gz: e9c63d2e67089f904a02b8c978e2a796dbe6e344565fa6bd589a1d3ad23bdcf6d80e16068b042c0b1ce386bf111313d06544dd8c351c4e76f8e8eddb182057c0
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Dieter Lunn
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# BootstrapMdEditor
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'bootstrap_md_editor'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install bootstrap_md_editor
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'BootstrapMdEditor'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'test'
|
31
|
+
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
task default: :test
|
@@ -0,0 +1,123 @@
|
|
1
|
+
$ ->
|
2
|
+
$('[data-toggle="tooltip"]').tooltip()
|
3
|
+
return
|
4
|
+
|
5
|
+
$ ->
|
6
|
+
$('[data-editor="h1"]').click ->
|
7
|
+
insertAtCaret('#md-editor textarea', '# Your title')
|
8
|
+
return
|
9
|
+
|
10
|
+
$ ->
|
11
|
+
$('[data-editor="h2"]').click ->
|
12
|
+
insertAtCaret('#md-editor textarea', '## Your title')
|
13
|
+
return
|
14
|
+
|
15
|
+
$ ->
|
16
|
+
$('[data-editor="h3"]').click ->
|
17
|
+
insertAtCaret('#md-editor textarea', '### Your title')
|
18
|
+
return
|
19
|
+
|
20
|
+
$ ->
|
21
|
+
$('[data-editor="h4"]').click ->
|
22
|
+
insertAtCaret('#md-editor textarea', '#### Your title')
|
23
|
+
return
|
24
|
+
|
25
|
+
$ ->
|
26
|
+
$('[data-editor="h5"]').click ->
|
27
|
+
insertAtCaret('#md-editor textarea', '##### Your title')
|
28
|
+
return
|
29
|
+
|
30
|
+
$ ->
|
31
|
+
$('[data-editor="italic"]').click ->
|
32
|
+
insertAtCaret('#md-editor textarea', '*Italic text*')
|
33
|
+
return
|
34
|
+
|
35
|
+
$ ->
|
36
|
+
$('[data-editor="bold"]').click ->
|
37
|
+
insertAtCaret('#md-editor textarea', '__Bold text__')
|
38
|
+
return
|
39
|
+
|
40
|
+
$ ->
|
41
|
+
$('[data-editor="ol"]').click ->
|
42
|
+
insertAtCaret('#md-editor textarea', "\n\n1. Item 1\n2. Item 2\n3. Item 3 \n\n")
|
43
|
+
return
|
44
|
+
|
45
|
+
$ ->
|
46
|
+
$('[data-editor="ul"]').click ->
|
47
|
+
insertAtCaret('#md-editor textarea', "\n\n* Item 1\n* Item 2\n* Item 3 \n\n")
|
48
|
+
return
|
49
|
+
|
50
|
+
$ ->
|
51
|
+
$('[data-editor="underline"]').click ->
|
52
|
+
insertAtCaret('#md-editor textarea', '_Underlined text_')
|
53
|
+
return
|
54
|
+
|
55
|
+
$ ->
|
56
|
+
$('[data-editor="table"]').click ->
|
57
|
+
insertAtCaret('#md-editor textarea', "\n|Header|Header|Header|\n|:------|:-------:|------:|\n|Left alignment|Centered|Right alignment|\n\n")
|
58
|
+
return
|
59
|
+
|
60
|
+
$ ->
|
61
|
+
$('[data-editor="link"]').click ->
|
62
|
+
insertAtCaret('#md-editor textarea', "\n[This is a link](http://google.com)\n")
|
63
|
+
return
|
64
|
+
|
65
|
+
$ ->
|
66
|
+
$('[data-editor="image"]').click ->
|
67
|
+
insertAtCaret('#md-editor textarea', "\n\n")
|
68
|
+
return
|
69
|
+
|
70
|
+
$ ->
|
71
|
+
$('[data-editor="preview"]').click ->
|
72
|
+
preview()
|
73
|
+
return
|
74
|
+
|
75
|
+
insertAtCaret = (areaId, text) ->
|
76
|
+
txtarea = $(areaId)[0]
|
77
|
+
if !txtarea
|
78
|
+
return
|
79
|
+
scrollPos = txtarea.scrollTop
|
80
|
+
strPos = 0
|
81
|
+
br = if txtarea.selectionStart or txtarea.selectionStart == '0' then 'ff' else if document.selection then 'ie' else false
|
82
|
+
if br is 'ie'
|
83
|
+
txtarea.focus()
|
84
|
+
range = document.selection.createRange()
|
85
|
+
range.moveStart 'character', -txtarea.value.length
|
86
|
+
strPos = range.text.length
|
87
|
+
else if br is 'ff'
|
88
|
+
strPos = txtarea.selectionStart
|
89
|
+
front = txtarea.value.substring(0, strPos)
|
90
|
+
back = txtarea.value.substring(strPos, txtarea.value.length)
|
91
|
+
txtarea.value = front + text + back
|
92
|
+
strPos = strPos + text.length
|
93
|
+
if br is 'ie'
|
94
|
+
txtarea.focus()
|
95
|
+
ieRange = document.selection.createRange()
|
96
|
+
ieRange.moveStart 'character', -txtarea.value.length
|
97
|
+
ieRange.moveStart 'character', strPos
|
98
|
+
ieRange.moveEnd 'character', 0
|
99
|
+
ieRange.select()
|
100
|
+
else if br is 'ff'
|
101
|
+
txtarea.selectionStart = strPos
|
102
|
+
txtarea.selectionEnd = strPos
|
103
|
+
txtarea.focus()
|
104
|
+
txtarea.scrollTop = scrollPos
|
105
|
+
return
|
106
|
+
|
107
|
+
preview = ->
|
108
|
+
if $('#md-editor').prop('hidden')
|
109
|
+
$('#md-preview').text('Preview')
|
110
|
+
$('#md-editor').removeAttr('hidden')
|
111
|
+
$('#md-preview-card').attr('hidden', 'true')
|
112
|
+
false
|
113
|
+
else
|
114
|
+
$.post(
|
115
|
+
'/editor/preview',
|
116
|
+
{md: $('#md-editor textarea').val()},
|
117
|
+
(data) ->
|
118
|
+
$('#md-preview').text('Editor')
|
119
|
+
$('#md-editor').attr('hidden', 'true')
|
120
|
+
$('#md-preview-card').removeAttr('hidden')
|
121
|
+
$('#md-preview-card .card-body').html(data)
|
122
|
+
)
|
123
|
+
return
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class EditorController < ApplicationController
|
2
|
+
def preview
|
3
|
+
options = {autolink: true, tables: true, hard_wrap: true, no_intra_emphasis: true, fenced_code:true, gh_blockcode: true, underline: true}
|
4
|
+
html = Redcarpet::Markdown.new(Redcarpet::Render::HTML, options).render(params['md']).html_safe
|
5
|
+
render html: html
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<div class="row mb-2">
|
2
|
+
<div class="col d-flex justify-content-center">
|
3
|
+
<%= render 'bootstrap_md_editor/toolbar' %>
|
4
|
+
</div>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<div class="row">
|
8
|
+
<div class="col">
|
9
|
+
<%= render 'bootstrap_md_editor/text_area', form: form, field: field %>
|
10
|
+
<%= render 'bootstrap_md_editor/preview' %>
|
11
|
+
</div>
|
12
|
+
</div>
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<div class="btn-toolbar" role="toolbar">
|
2
|
+
<div class="dropdown mr-2">
|
3
|
+
<button id="headerMenuButton" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
4
|
+
Headers
|
5
|
+
</button>
|
6
|
+
<div class="dropdown-menu" aria-labelledby="headerMenuButton">
|
7
|
+
<button class="dropdown-item" data-editor="h1">H1</button>
|
8
|
+
<button class="dropdown-item" data-editor="h2">H2</button>
|
9
|
+
<button class="dropdown-item" data-editor="h3">H3</button>
|
10
|
+
<button class="dropdown-item" data-editor="h4">H4</button>
|
11
|
+
<button class="dropdown-item" data-editor="h5">H5</button>
|
12
|
+
</div>
|
13
|
+
</div>
|
14
|
+
|
15
|
+
<div class="btn-group mr-2" role="group">
|
16
|
+
<button class="btn btn-light btn-sm" data-toggle="tooltip" title="Italic" data-placement="top" data-editor="italic">
|
17
|
+
<%= icon('italic') %>
|
18
|
+
</button>
|
19
|
+
<button class="btn btn-light btn-sm" data-toggle="tooltip" title="Bold" data-placement="top" data-editor="bold">
|
20
|
+
<%= icon('bold') %>
|
21
|
+
</button>
|
22
|
+
<button class="btn btn-light btn-sm" data-toggle="tooltip" data-placement="top" title="Unordered list" data-editor="ul">
|
23
|
+
<%= icon('list-ul') %>
|
24
|
+
</button>
|
25
|
+
<button class="btn btn-light btn-sm" data-toggle="tooltip" data-placement="top" title="Ordered list" data-editor="ol">
|
26
|
+
<%= icon('list-ol') %>
|
27
|
+
</button>
|
28
|
+
<button class="btn btn-light btn-sm" data-toggle="tooltip" data-placement="top" title="Indent">
|
29
|
+
<%= icon('indent') %>
|
30
|
+
</button>
|
31
|
+
<button class="btn btn-light btn-sm" data-toggle="tooltip" data-placement="top" title="Underline" data-editor="underline">
|
32
|
+
<%= icon('underline') %>
|
33
|
+
</button>
|
34
|
+
<button class="btn btn-light btn-sm" data-toggle="tooltip" data-placement="top" title="Table" data-editor="table">
|
35
|
+
<%= icon('table') %>
|
36
|
+
</button>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div class="btn-group mr-2" role="group">
|
40
|
+
<button class="btn btn-light btn-sm" data-toggle="tooltip" data-placement="top" title="Link" data-editor="link">
|
41
|
+
<%= icon('link') %>
|
42
|
+
</button>
|
43
|
+
<button class="btn btn-light btn-sm" data-toggle="tooltip" data-placement="top" title="Image" data-editor="image">
|
44
|
+
<%= icon('image') %>
|
45
|
+
</button>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<button id="md-preview" class="btn btn-info btn-sm" data-editor="preview">
|
49
|
+
Preview
|
50
|
+
</button>
|
51
|
+
</div>
|
data/config/routes.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bootstrap_md_editor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dieter Lunn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.1.4
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.1.4
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bootstrap-sass
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 4.0.0.beta
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 4.0.0.beta
|
47
|
+
description: Simple Markdown editor styled with Bootstrap
|
48
|
+
email:
|
49
|
+
- coder2000@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- app/assets/javascripts/bootstrap_md_editor.coffee
|
58
|
+
- app/controllers/editor_controller.rb
|
59
|
+
- app/helpers/bootstrap_md_editor/view_helpers.rb
|
60
|
+
- app/views/bootstrap_md_editor/_editor.html.erb
|
61
|
+
- app/views/bootstrap_md_editor/_preview.html.erb
|
62
|
+
- app/views/bootstrap_md_editor/_text_area.html.erb
|
63
|
+
- app/views/bootstrap_md_editor/_toolbar.html.erb
|
64
|
+
- config/routes.rb
|
65
|
+
- lib/bootstrap_md_editor.rb
|
66
|
+
- lib/bootstrap_md_editor/engine.rb
|
67
|
+
- lib/bootstrap_md_editor/railtie.rb
|
68
|
+
- lib/bootstrap_md_editor/version.rb
|
69
|
+
homepage: http://github.com/coder2000/bootstrap_md_editor
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.6.13
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Markdown editor with Bootstrap 4
|
93
|
+
test_files: []
|