hallo_rails 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -5
- data/lib/hallo_rails/version.rb +1 -1
- data/lib/hallo_rails.rb +10 -3
- data/vendor/assets/javascripts/hallo_rails.js.coffee +1 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# HalloRails
|
2
2
|
|
3
|
-
|
3
|
+
Use the Hallo Editor (https://github.com/bergie/hallo) to edit content in place in your Rails app.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -12,13 +12,50 @@ And then execute:
|
|
12
12
|
|
13
13
|
$ bundle
|
14
14
|
|
15
|
-
|
15
|
+
Add this to your javascript manifest file:
|
16
16
|
|
17
|
-
|
17
|
+
//= require rangy-core
|
18
|
+
//= require hallo
|
19
|
+
//= require hallo_rails
|
18
20
|
|
19
|
-
##
|
21
|
+
## Requirements
|
20
22
|
|
21
|
-
|
23
|
+
jQuery and jQuery UI. A good way of including jQuery UI in your rails app is using the jquery-ui-rails gem.
|
24
|
+
|
25
|
+
## Basic Usage
|
26
|
+
|
27
|
+
Hallo Rails provides 2 view helpers to make Rails model fields editable.
|
28
|
+
Say you have an article model with a field 'content'. Outside a form use:
|
29
|
+
|
30
|
+
= editable @article, :content
|
31
|
+
|
32
|
+
Within a form use
|
33
|
+
|
34
|
+
= form_editable @article, :content
|
35
|
+
|
36
|
+
And make sure to call
|
37
|
+
|
38
|
+
HalloRails.init() after the dom has loaded, e.g. like:
|
39
|
+
|
40
|
+
jQuery ->
|
41
|
+
HalloRails.init()
|
42
|
+
|
43
|
+
Hallo Rails will save edited content each time the editable area is left, using the default rails url for updating models:
|
44
|
+
|
45
|
+
"#{object_name.pluralize}/#{object.to_param}"
|
46
|
+
|
47
|
+
For the article example this could be for example: "articles/24".
|
48
|
+
|
49
|
+
You can change this url by supplying it to the editable helper:
|
50
|
+
|
51
|
+
= editable @article, :content, update_url: "my_own/url/to_update/the/model"
|
52
|
+
|
53
|
+
If you use the form_editable helper, the content is only saved once the form is submitted.
|
54
|
+
|
55
|
+
|
56
|
+
## Advanced usage
|
57
|
+
|
58
|
+
Check the source code ;-) (for now)
|
22
59
|
|
23
60
|
## Contributing
|
24
61
|
|
data/lib/hallo_rails/version.rb
CHANGED
data/lib/hallo_rails.rb
CHANGED
@@ -20,13 +20,17 @@ module HalloRails
|
|
20
20
|
object_name = object.class.to_s.underscore
|
21
21
|
options.reverse_merge! tag: :div,
|
22
22
|
content: object.send(method).try(:html_safe),
|
23
|
-
update_url: "#{
|
23
|
+
update_url: "#{object_name.pluralize}/#{object.to_param}",
|
24
24
|
blank_text: "<i>Click to Edit</i>".html_safe
|
25
25
|
|
26
26
|
content_tag options[:tag], options[:content].present? ? options[:content] : options[:blank_text],
|
27
27
|
class: "#{'editable' if !options.has_key?(:editable) or options[:editable]}",
|
28
28
|
id: "#{object_name}_#{method.to_s}",
|
29
|
-
data: { update_url: options[:update_url],
|
29
|
+
data: { update_url: options[:update_url],
|
30
|
+
model: object_name,
|
31
|
+
method: method.to_s,
|
32
|
+
editable_options: options[:hallo_options],
|
33
|
+
editable_plugins: options[:plugins] }.merge(options[:params] || {})
|
30
34
|
end
|
31
35
|
|
32
36
|
|
@@ -39,7 +43,10 @@ module HalloRails
|
|
39
43
|
content_tag( options[:tag], options[:content].present? ? options[:content] : options[:blank_text],
|
40
44
|
class: 'form_editable',
|
41
45
|
id: "#{object_name}_#{method.to_s}",
|
42
|
-
data: { model: object_name,
|
46
|
+
data: { model: object_name,
|
47
|
+
method: method.to_s,
|
48
|
+
editable_options: options[:hallo_options],
|
49
|
+
editable_plugins: options[:plugins] }.merge(options[:params] || {})) +
|
43
50
|
text_area_tag( "#{object_name}[#{method}]", options[:content], style: "display:none" )
|
44
51
|
end
|
45
52
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hallo_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
59
|
version: '0'
|
60
60
|
segments:
|
61
61
|
- 0
|
62
|
-
hash:
|
62
|
+
hash: 4399511932397100775
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: '0'
|
69
69
|
segments:
|
70
70
|
- 0
|
71
|
-
hash:
|
71
|
+
hash: 4399511932397100775
|
72
72
|
requirements: []
|
73
73
|
rubyforge_project:
|
74
74
|
rubygems_version: 1.8.24
|