simple_form_wysihtml 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +130 -0
- data/Rakefile +2 -0
- data/lib/assets/javascripts/simple_form_wysihtml.js +3 -0
- data/lib/assets/javascripts/simple_form_wysihtml/simple_form_wysihtml.js.coffee.erb +18 -0
- data/lib/assets/javascripts/simple_form_wysihtml/simple_form_wysihtml_parser_rules.js +37 -0
- data/lib/assets/stylesheets/simple_form_wysihtml.css.scss +23 -0
- data/lib/simple_form_wysihtml.rb +15 -0
- data/lib/simple_form_wysihtml/configuration.rb +17 -0
- data/lib/simple_form_wysihtml/engine.rb +6 -0
- data/lib/simple_form_wysihtml/simple_form_wysihtml.rb +308 -0
- data/lib/simple_form_wysihtml/version.rb +3 -0
- data/simple_form_wysihtml.gemspec +26 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d9101c670f1be008a11428b9d7d3a69d3be0f84
|
4
|
+
data.tar.gz: c931b10c95007d6dbcc4fa39147372de9442ad38
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1949ca6a611e6e718647d65336128d5bfb7a16a4d986e82f31df8cf0b08d6ffeee3320271bedb814f5097e8e4675795b562232f05250701616f2d6e76cda3db4
|
7
|
+
data.tar.gz: 4b89fbdad6d35a2351057c2962cef069f6dc1fabd2db8ff77eef022a33a0153f13cf10e3c249e684382feedc31179de8c59ef6ac7f843d1bc18beb4fdfdb798c
|
data/.gitignore
ADDED
@@ -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
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.
|
data/README.md
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
# Simple Form Wysihtml
|
2
|
+
|
3
|
+
Integrates [Wysihtml5](http://xing.github.io/wysihtml5) editor (resp. [this branch](https://github.com/Edicy/wysihtml5) of it) with Rails and [Simple Form](https://github.com/plataformatec/simple_form).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the gem to your Gemfile:
|
8
|
+
|
9
|
+
gem 'simple_form_wysihtml'
|
10
|
+
|
11
|
+
And execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install simple_form_wysihtml
|
18
|
+
|
19
|
+
To make it work you need to require the javascripts in `application.js`:
|
20
|
+
|
21
|
+
//= require simple_form_wysihtml
|
22
|
+
|
23
|
+
Optionally you can add the (very minimal) default styling in `application.css`:
|
24
|
+
|
25
|
+
*= require 'simple_form_wysihtml'
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Use in forms:
|
30
|
+
|
31
|
+
= form.input :body, as: :wysihtml
|
32
|
+
|
33
|
+
## Styling
|
34
|
+
|
35
|
+
See [simple_form_wysihtml.css.scss](https://github.com/tomasc/simple_form_wysihtml/blob/master/lib/assets/stylesheets/simple_form_wysihtml.css.scss) for how to style the editor.
|
36
|
+
|
37
|
+
## Configuration
|
38
|
+
|
39
|
+
### The toolbar
|
40
|
+
|
41
|
+
You can override the defaults by specifying the toolbar in an initializer:
|
42
|
+
|
43
|
+
```Ruby
|
44
|
+
# config/initializers/simple_form_wysihtml.rb
|
45
|
+
|
46
|
+
SimpleFormWysihtml::WysihtmlInput.configure do |c|
|
47
|
+
c.commands = [
|
48
|
+
{ bold: { label: 'Bold' }, italic: { label: 'Italic' } },
|
49
|
+
{ createLink: { label: 'Create Link' } },
|
50
|
+
{ insertOrderedList: nil, insertUnorderedList: nil }
|
51
|
+
]
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Alternatively, you can configure individual input fields in the form:
|
56
|
+
|
57
|
+
```Slim
|
58
|
+
= f.input :body, as: :wysihtml, commands: [{ bold: { label: 'B' } }, { italic: { label: 'I' } }]
|
59
|
+
```
|
60
|
+
|
61
|
+
See the [list of available commands](https://github.com/Edicy/wysihtml5/tree/master/src/commands).
|
62
|
+
|
63
|
+
### Parser rules
|
64
|
+
|
65
|
+
The parser rules are defined as a javascript variable, containing a hash of rules (see [Wysihtml5x](https://github.com/Edicy/wysihtml5/tree/master/parser_rules).
|
66
|
+
|
67
|
+
Add a javascript file with your own parser rules (namespaced for example like this):
|
68
|
+
|
69
|
+
```js
|
70
|
+
// app/assets/javascripts/parser_rules.js
|
71
|
+
|
72
|
+
YourCoolNameSpace = (function(){
|
73
|
+
|
74
|
+
var YourCoolNameSpace = {
|
75
|
+
parserRules: {
|
76
|
+
tags: {
|
77
|
+
i: {
|
78
|
+
rename_tag: 'em'
|
79
|
+
},
|
80
|
+
|
81
|
+
a: {
|
82
|
+
set_attributes: {
|
83
|
+
target: "_self"
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
return YourCoolNameSpace;
|
91
|
+
})();
|
92
|
+
```
|
93
|
+
|
94
|
+
Then in your initializer assign the `parser_rules` to the name of your JS variable:
|
95
|
+
|
96
|
+
```Ruby
|
97
|
+
# config/initializers/simple_form_wysihtml.rb
|
98
|
+
|
99
|
+
SimpleFormWysihtml::WysihtmlInput.configure do |c|
|
100
|
+
c.parser_rules = 'YourCoolNameSpace.parserRules'
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
## TODO
|
105
|
+
|
106
|
+
### Add remaining commands from wysihtml5:
|
107
|
+
|
108
|
+
* addTableCells
|
109
|
+
* bgColorStyle
|
110
|
+
* removeLink
|
111
|
+
* createTable
|
112
|
+
* deleteTableCells
|
113
|
+
* fontSizeStyle
|
114
|
+
* foreColorStyle
|
115
|
+
* justifyFull
|
116
|
+
* mergeTableCells
|
117
|
+
|
118
|
+
Reference: [wysihtml5 wiki](https://github.com/edicy/wysihtml5/wiki/Supported-Commands).
|
119
|
+
|
120
|
+
### Testing
|
121
|
+
|
122
|
+
How to do it?
|
123
|
+
|
124
|
+
## Contributing
|
125
|
+
|
126
|
+
1. Fork it ( https://github.com/[my-github-username]/simple_form_wysihtml/fork )
|
127
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
128
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
129
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
130
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
$ ->
|
5
|
+
editors = []
|
6
|
+
|
7
|
+
$('div.wysihtml_editor').each (idx, wrapper) ->
|
8
|
+
e = new wysihtml5.Editor(
|
9
|
+
$(wrapper).find('textarea').get(0)
|
10
|
+
toolbar: $(wrapper).find('div.toolbar').get(0)
|
11
|
+
parserRules: <%= SimpleFormWysihtml::WysihtmlInput.configuration.parser_rules %>
|
12
|
+
# useLineBreaks: false
|
13
|
+
# cleanUp: true
|
14
|
+
)
|
15
|
+
# showToolbarAfterInit: false
|
16
|
+
editors.push(e)
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// Sets up some sensible defaults
|
2
|
+
|
3
|
+
SimpleFormWysihtml = (function(){
|
4
|
+
|
5
|
+
var SimpleFormWysihtml = {
|
6
|
+
parserRules: {
|
7
|
+
tags: {
|
8
|
+
strong: {},
|
9
|
+
b: {
|
10
|
+
rename_tag: 'strong'
|
11
|
+
},
|
12
|
+
i: {
|
13
|
+
rename_tag: 'em'
|
14
|
+
},
|
15
|
+
em: {},
|
16
|
+
br: {},
|
17
|
+
p: {},
|
18
|
+
div: {},
|
19
|
+
span: {},
|
20
|
+
ul: {},
|
21
|
+
ol: {},
|
22
|
+
li: {},
|
23
|
+
a: {
|
24
|
+
set_attributes: {
|
25
|
+
target: "_self",
|
26
|
+
rel: "nofollow"
|
27
|
+
},
|
28
|
+
check_attributes: {
|
29
|
+
href: "url"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
return SimpleFormWysihtml;
|
37
|
+
})();
|
@@ -0,0 +1,23 @@
|
|
1
|
+
div.wysihtml_editor {
|
2
|
+
div.toolbar {
|
3
|
+
ul.commands {
|
4
|
+
margin: 0;
|
5
|
+
padding: 0;
|
6
|
+
|
7
|
+
li.command_group {
|
8
|
+
display: inline-block;
|
9
|
+
|
10
|
+
a.command.button {
|
11
|
+
margin-right: .5em;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
div.dialogs {
|
16
|
+
div.dialog {
|
17
|
+
a.button {
|
18
|
+
margin-right: .5em;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "simple_form"
|
2
|
+
require "simple_form_wysihtml/engine"
|
3
|
+
require "simple_form_wysihtml/configuration"
|
4
|
+
require "simple_form_wysihtml/simple_form_wysihtml"
|
5
|
+
require "simple_form_wysihtml/version"
|
6
|
+
|
7
|
+
require "rails-assets-wysihtml5x"
|
8
|
+
|
9
|
+
# ---------------------------------------------------------------------
|
10
|
+
|
11
|
+
module SimpleForm
|
12
|
+
class FormBuilder
|
13
|
+
map_type :wysihtml, to: SimpleFormWysihtml::WysihtmlInput
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SimpleFormWysihtml
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
attr_accessor :commands, :parser_rules
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@parser_rules = 'SimpleFormWysihtml.parserRules'
|
8
|
+
@commands = [
|
9
|
+
{ bold: { label: 'B' }, italic: { label: 'I' } },
|
10
|
+
{ createLink: nil },
|
11
|
+
{ insertOrderedList: nil, insertUnorderedList: nil },
|
12
|
+
{ undo: nil, redo: nil }
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,308 @@
|
|
1
|
+
module SimpleFormWysihtml
|
2
|
+
class WysihtmlInput < 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
|
+
template.content_tag :div, class: %w(wysihtml_editor) do
|
24
|
+
toolbar + text_area
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private # =============================================================
|
29
|
+
|
30
|
+
# Array of commands for text area toolbar, arranged into command groups.
|
31
|
+
# @return [Array]
|
32
|
+
def command_list
|
33
|
+
options[:commands] || SimpleFormWysihtml::WysihtmlInput.configuration.commands
|
34
|
+
end
|
35
|
+
|
36
|
+
# ---------------------------------------------------------------------
|
37
|
+
|
38
|
+
# @return [String]
|
39
|
+
def text_area
|
40
|
+
@builder.text_area(attribute_name, input_html_options).html_safe
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [String]
|
44
|
+
def toolbar
|
45
|
+
template.content_tag :div, class: 'toolbar' do
|
46
|
+
commands + dialogs
|
47
|
+
end.html_safe
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [String]
|
51
|
+
def commands
|
52
|
+
template.content_tag :ul, class: 'commands' do
|
53
|
+
command_list.collect do |group|
|
54
|
+
command_group(group)
|
55
|
+
end.join.html_safe
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# @param [Array] group
|
60
|
+
# @return [String]
|
61
|
+
def command_group group
|
62
|
+
template.content_tag :li, class: 'command_group' do
|
63
|
+
group.map do |command, options|
|
64
|
+
self.send(command, options || {})
|
65
|
+
end.join.html_safe
|
66
|
+
end.html_safe
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param [String]
|
70
|
+
def dialogs
|
71
|
+
flattened_command_list = command_list.inject({}){ |res, i| res.merge!(i) }
|
72
|
+
command_list_with_dialog = flattened_command_list.select{ |k,v| %w(createLink insertImage).include?(k.to_s) }
|
73
|
+
|
74
|
+
return unless command_list_with_dialog.present?
|
75
|
+
|
76
|
+
template.content_tag :div, class: 'dialogs' do
|
77
|
+
command_list_with_dialog.map do |command, options|
|
78
|
+
self.send("#{command}_dialog", options || {})
|
79
|
+
end.join.html_safe
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# ---------------------------------------------------------------------
|
84
|
+
|
85
|
+
# @param [Hash] options
|
86
|
+
# @return [String]
|
87
|
+
def bold options={}
|
88
|
+
label = options[:label] || 'Bold'
|
89
|
+
|
90
|
+
command_tag 'bold', label
|
91
|
+
end
|
92
|
+
|
93
|
+
# @param [Hash] options
|
94
|
+
# @return [String]
|
95
|
+
def createLink options={}
|
96
|
+
label = options[:label] || 'Link'
|
97
|
+
value = options[:value] || 'http://'
|
98
|
+
|
99
|
+
command_tag('createLink', label, value)
|
100
|
+
end
|
101
|
+
|
102
|
+
# @param [Hash] options
|
103
|
+
# @return [String]
|
104
|
+
def createLink_dialog options={}
|
105
|
+
dialog_label = options[:dialog_label] || 'Link:'
|
106
|
+
value = options[:value] || 'http://'
|
107
|
+
dialog_field = dialog_field_tag('href', value)
|
108
|
+
|
109
|
+
dialog_tag('createLink', dialog_label, dialog_field)
|
110
|
+
end
|
111
|
+
|
112
|
+
# @param [Hash] options
|
113
|
+
# @retun [String]
|
114
|
+
def fontSize options={}
|
115
|
+
label = options[:label] || 'Size'
|
116
|
+
value = options[:value] || 'small'
|
117
|
+
|
118
|
+
command_tag 'fontSize', label, value
|
119
|
+
end
|
120
|
+
|
121
|
+
# @param [Hash] options
|
122
|
+
# @return [String]
|
123
|
+
def foreColor options={}
|
124
|
+
label = options[:label] || 'Color'
|
125
|
+
value = options[:label] || 'red'
|
126
|
+
|
127
|
+
command_tag 'foreColor', label, value
|
128
|
+
end
|
129
|
+
|
130
|
+
# @param [Hash] options
|
131
|
+
# @return [String]
|
132
|
+
def formatBlock options={}
|
133
|
+
label = options[:label] || 'Block'
|
134
|
+
value = options[:value] || 'h1'
|
135
|
+
|
136
|
+
command_tag 'formatBlock', label, value
|
137
|
+
end
|
138
|
+
|
139
|
+
# @param [Hash] options
|
140
|
+
# @return [String]
|
141
|
+
def formatInline options={}
|
142
|
+
label = options[:label] || 'Inline'
|
143
|
+
value = options[:value] || 'span'
|
144
|
+
|
145
|
+
command_tag 'formatInline', label, value
|
146
|
+
end
|
147
|
+
|
148
|
+
# @param [Hash] options
|
149
|
+
# @return [String]
|
150
|
+
def insertHTML options={}
|
151
|
+
label = options[:label] || 'HTML'
|
152
|
+
value = options[:value] || '<blockquote>foobar</blockquote>'
|
153
|
+
|
154
|
+
command_tag 'insertHTML', label, value
|
155
|
+
end
|
156
|
+
|
157
|
+
# @param [Hash] options
|
158
|
+
# @return [String]
|
159
|
+
def insertImage options={}
|
160
|
+
label = options[:label] || 'Image'
|
161
|
+
value = options[:value] || 'http://'
|
162
|
+
|
163
|
+
command_tag('insertImage', label)
|
164
|
+
end
|
165
|
+
|
166
|
+
# @param [Hash] options
|
167
|
+
# @return [String]
|
168
|
+
def insertImage_dialog options={}
|
169
|
+
dialog_label = options[:dialog_label] || 'Image:'
|
170
|
+
value = options[:value] || 'http://'
|
171
|
+
dialog_field = dialog_field_tag('src', value)
|
172
|
+
|
173
|
+
dialog_tag('createLink', dialog_label, dialog_field)
|
174
|
+
end
|
175
|
+
|
176
|
+
# @param [Hash] options
|
177
|
+
# @return [String]
|
178
|
+
def insertLineBreak options={}
|
179
|
+
label = options[:label] || 'Line Break'
|
180
|
+
|
181
|
+
command_tag 'insertLineBreak', label
|
182
|
+
end
|
183
|
+
|
184
|
+
# @param [Hash] options
|
185
|
+
# @return [String]
|
186
|
+
def insertOrderedList options={}
|
187
|
+
label = options[:label] || 'OL'
|
188
|
+
|
189
|
+
command_tag 'insertOrderedList', label
|
190
|
+
end
|
191
|
+
|
192
|
+
# @param [Hash] options
|
193
|
+
# @return [String]
|
194
|
+
def insertUnorderedList options={}
|
195
|
+
label = options[:label] || 'UL'
|
196
|
+
|
197
|
+
command_tag 'insertUnorderedList', label
|
198
|
+
end
|
199
|
+
|
200
|
+
# @param [Hash] options
|
201
|
+
# @return [String]
|
202
|
+
def italic options={}
|
203
|
+
label = options[:label] || 'Italic'
|
204
|
+
|
205
|
+
command_tag 'italic', label
|
206
|
+
end
|
207
|
+
|
208
|
+
# @param [Hash] options
|
209
|
+
# @return [String]
|
210
|
+
def justifyCenter options={}
|
211
|
+
label = options[:label] || 'Center'
|
212
|
+
|
213
|
+
command_tag 'justifyCenter', label
|
214
|
+
end
|
215
|
+
|
216
|
+
# @param [Hash] options
|
217
|
+
# @return [String]
|
218
|
+
def justifyLeft options={}
|
219
|
+
label = options[:label] || 'Left'
|
220
|
+
|
221
|
+
command_tag 'justifyLeft', label
|
222
|
+
end
|
223
|
+
|
224
|
+
# @param [Hash] options
|
225
|
+
# @return [String]
|
226
|
+
def justifyRight options
|
227
|
+
label = options[:label] || 'Right'
|
228
|
+
|
229
|
+
command_tag 'justifyRight', label
|
230
|
+
end
|
231
|
+
|
232
|
+
# @param [Hash] options
|
233
|
+
# @return [String]
|
234
|
+
def redo options={}
|
235
|
+
label = options[:label] || 'Redo'
|
236
|
+
|
237
|
+
command_tag 'redo', label
|
238
|
+
end
|
239
|
+
|
240
|
+
# @param [Hash] options
|
241
|
+
# @return [String]
|
242
|
+
def underline options={}
|
243
|
+
label = options[:label] || 'Underline'
|
244
|
+
|
245
|
+
command_tag 'underline', label
|
246
|
+
end
|
247
|
+
|
248
|
+
# @param [Hash] options
|
249
|
+
# @return [String]
|
250
|
+
def undo options={}
|
251
|
+
label = options[:label] || 'Undo'
|
252
|
+
|
253
|
+
command_tag 'undo', label
|
254
|
+
end
|
255
|
+
|
256
|
+
# ---------------------------------------------------------------------
|
257
|
+
|
258
|
+
# Generates link for specified command
|
259
|
+
#
|
260
|
+
# @param [String] command
|
261
|
+
# @param [String] label
|
262
|
+
# @param [String] value
|
263
|
+
# @return [String]
|
264
|
+
def command_tag command, label, value=nil
|
265
|
+
options = { 'data-wysihtml5-command' => command }
|
266
|
+
options.merge!({ 'data-wysihtml5-command-value' => value }) if value.present?
|
267
|
+
options.merge!({ class: 'command button' })
|
268
|
+
|
269
|
+
template.content_tag :a, options do
|
270
|
+
label
|
271
|
+
end.html_safe
|
272
|
+
end
|
273
|
+
|
274
|
+
# @param [String] command
|
275
|
+
# @param [String] label
|
276
|
+
# @param [String] dialog_field
|
277
|
+
# @return [String]
|
278
|
+
def dialog_tag command, label, dialog_field
|
279
|
+
options = { 'data-wysihtml5-dialog' => command, style: 'display: none' }
|
280
|
+
options.merge!({ class: 'dialog' })
|
281
|
+
|
282
|
+
template.content_tag :div, options do
|
283
|
+
template.content_tag(:label, (label + dialog_field).html_safe).html_safe +
|
284
|
+
action_tag('save', 'OK') +
|
285
|
+
action_tag('cancel', 'Cancel')
|
286
|
+
end.html_safe
|
287
|
+
end
|
288
|
+
|
289
|
+
# @param [String] action
|
290
|
+
# @param [String] label
|
291
|
+
# @return [String]
|
292
|
+
def action_tag action, label
|
293
|
+
template.content_tag :a, 'data-wysihtml5-dialog-action' => action, class: 'button' do
|
294
|
+
label
|
295
|
+
end.html_safe
|
296
|
+
end
|
297
|
+
|
298
|
+
# @param [String] att
|
299
|
+
# @param [String] value
|
300
|
+
# @return [String]
|
301
|
+
def dialog_field_tag att, value=nil
|
302
|
+
"<input data-wysihtml5-dialog-field='#{att}' value='#{value}'>".html_safe
|
303
|
+
end
|
304
|
+
|
305
|
+
# ---------------------------------------------------------------------
|
306
|
+
|
307
|
+
end
|
308
|
+
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_wysihtml/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple_form_wysihtml"
|
8
|
+
spec.version = SimpleFormWysihtml::VERSION
|
9
|
+
spec.authors = ["Tomas Celizna"]
|
10
|
+
spec.email = ["tomas.celizna@gmail.com"]
|
11
|
+
spec.summary = %q{Integrates Wysihtml5 editor with Rails and Simple Form.}
|
12
|
+
spec.description = %q{Integrates Wysihtml5 editor 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-wysihtml5x", ">= 0.4.12"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_form_wysihtml
|
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-14 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-wysihtml5x
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.12
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.4.12
|
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 Wysihtml5 editor 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_wysihtml.js
|
82
|
+
- lib/assets/javascripts/simple_form_wysihtml/simple_form_wysihtml.js.coffee.erb
|
83
|
+
- lib/assets/javascripts/simple_form_wysihtml/simple_form_wysihtml_parser_rules.js
|
84
|
+
- lib/assets/stylesheets/simple_form_wysihtml.css.scss
|
85
|
+
- lib/simple_form_wysihtml.rb
|
86
|
+
- lib/simple_form_wysihtml/configuration.rb
|
87
|
+
- lib/simple_form_wysihtml/engine.rb
|
88
|
+
- lib/simple_form_wysihtml/simple_form_wysihtml.rb
|
89
|
+
- lib/simple_form_wysihtml/version.rb
|
90
|
+
- simple_form_wysihtml.gemspec
|
91
|
+
homepage: https://github.com/tomasc/simple_form_wysihtml
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.1.10
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Integrates Wysihtml5 editor with Rails and Simple Form.
|
115
|
+
test_files: []
|
116
|
+
has_rdoc:
|