rails_embed_editor 1.0.0 → 1.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.
- checksums.yaml +8 -8
- data/app/assets/javascripts/rails_embed_editor/application.coffee +15 -4
- data/app/controllers/rails_embed_editor/editor_controller.rb +2 -0
- data/app/helpers/rails_embed_editor/application_helper.rb +1 -1
- data/lib/rails_embed_editor/file_manager.rb +7 -2
- data/lib/rails_embed_editor/version.rb +1 -1
- data/test/dummy/db/development.sqlite3 +0 -0
- metadata +4 -30
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmI2OGM1NTBjZDQzZTk5MzQ0OTgwNDBhZmE3NTNkYzhjNzAyNTYzZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTRiMTE2ODY2OGIwODFiYjdhNjFmZDkzYWQyOGE2YTE5NzdhOWYzYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTA4ZTZjNzVmMGI1N2ZmMzBhMDVjNmVjMDYwMDdhMTc0MThlMWMzZmI5YTll
|
10
|
+
ZTE1NjliMTYwMmJjMDQ3OWNmZDQ3Y2FlZDMxYzY1NjNlZTBiZmNmZjAzZWIz
|
11
|
+
OTExNGQ3ZGRiMDlmYTQzODJkODRkZDMxYWI5MmM0MGY5YTYzZWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTY2ZjhlYTg5YWRiNDc0NDViZDEzZTQwMzkyOGZkY2ZmNmJhZjIzYTc4N2U2
|
14
|
+
MTlkYjRhMDVkYjgwNjlhZDJhZWJmN2QxNjBmMDllYmQ1YTgxYWM1NzkxZWMz
|
15
|
+
OWViZWU0NTEyMWRiMmFiY2JiZjk0NzZmZWNmZThkNWQ5MTQ5MTA=
|
@@ -23,7 +23,7 @@ window.load_rails_embed_code_editor = () ->
|
|
23
23
|
editormode: container.data('editormode')
|
24
24
|
highlight: compute_range(container.data('highlight'), container.data('first-line'))
|
25
25
|
}
|
26
|
-
setup_editor(container
|
26
|
+
setup_editor(container, options)
|
27
27
|
|
28
28
|
|
29
29
|
setup_editor = (element, options) ->
|
@@ -34,7 +34,7 @@ setup_editor = (element, options) ->
|
|
34
34
|
editormode: 'readonly'
|
35
35
|
}
|
36
36
|
options = $.extend({}, defaults, options);
|
37
|
-
editor = ace.edit(element)
|
37
|
+
editor = ace.edit(element[0])
|
38
38
|
editor.commands.removeCommand('replace')
|
39
39
|
editor.setTheme("ace/theme/" + options['theme']);
|
40
40
|
editor.getSession().setMode("ace/mode/" + options['mode']);
|
@@ -44,6 +44,13 @@ setup_editor = (element, options) ->
|
|
44
44
|
editor.setOption("maxLines", 40);
|
45
45
|
editor.setOption("minLines", 5);
|
46
46
|
|
47
|
+
#highlight the current line only if its focus
|
48
|
+
editor.setHighlightActiveLine(false)
|
49
|
+
editor.on "focus", () ->
|
50
|
+
editor.setHighlightActiveLine(true)
|
51
|
+
editor.on "blur", () ->
|
52
|
+
editor.setHighlightActiveLine(false)
|
53
|
+
|
47
54
|
editor.getSession().addMarker(options['highlight'], "editor_highlight", "text") unless options['highlight'] == null
|
48
55
|
|
49
56
|
if options['editormode'] != 'readonly'
|
@@ -57,15 +64,19 @@ setup_editor = (element, options) ->
|
|
57
64
|
button.text('Save')
|
58
65
|
editor.setReadOnly(false)
|
59
66
|
else
|
67
|
+
last_line = editor.session.getLength() - options['first_line']+1
|
60
68
|
$.post('/rails_embed_editor/edit', {
|
61
|
-
content: editor.getValue()
|
69
|
+
content: editor.getValue() + '\n'
|
62
70
|
first_line: options['first_line']
|
63
71
|
last_line: options['last_line']
|
64
72
|
filename: options['filename']
|
65
73
|
}).success (data) ->
|
66
74
|
if data['success'] == true
|
67
75
|
button.text('Saved!')
|
68
|
-
|
76
|
+
console.log('last: ' + options['last_line'])
|
77
|
+
console.log('new: ' + last_line)
|
78
|
+
element.attr('data-last-line', last_line)
|
79
|
+
options['last_line'] = last_line
|
69
80
|
else
|
70
81
|
button.text('Error')
|
71
82
|
console.log('Error saving:' + data['message'])
|
@@ -11,6 +11,8 @@ module RailsEmbedEditor
|
|
11
11
|
if filename.nil? or text.nil?
|
12
12
|
render :json => {:success => false, :params => params.to_json}
|
13
13
|
else
|
14
|
+
puts text.lines.map{|x| "#{x.chomp}\n"}.to_s
|
15
|
+
p text
|
14
16
|
manager = RailsEmbedEditor::FileManager.from_options(filename, params)
|
15
17
|
manager.save_text text
|
16
18
|
render :json => {:success => true}
|
@@ -3,7 +3,7 @@ module RailsEmbedEditor
|
|
3
3
|
def rails_embed_editor(filename, options ={})
|
4
4
|
options[:editormode] ||= RailsEmbedEditor::EditorMode::READ_ONLY
|
5
5
|
manager = RailsEmbedEditor::FileManager.from_options(filename, options)
|
6
|
-
text = manager.read_text
|
6
|
+
text = manager.read_text.chomp
|
7
7
|
first_line = manager.first_line
|
8
8
|
last_line = manager.last_line
|
9
9
|
content_tag('div', text, :class => 'rails_embed_code_editor',
|
@@ -25,7 +25,10 @@ module RailsEmbedEditor
|
|
25
25
|
def read_lines
|
26
26
|
lines = []
|
27
27
|
File.open(@filename, 'r') do |f|
|
28
|
-
|
28
|
+
all_lines = f.readlines
|
29
|
+
@first_line = 1 if @first_line <= 0
|
30
|
+
@last_line = all_lines.size if @first_line > all_lines.size
|
31
|
+
lines = all_lines[@first_line-1...@last_line]
|
29
32
|
end
|
30
33
|
lines
|
31
34
|
end
|
@@ -35,7 +38,7 @@ module RailsEmbedEditor
|
|
35
38
|
end
|
36
39
|
|
37
40
|
def save_text(text)
|
38
|
-
save_lines(text.
|
41
|
+
save_lines(text.lines.map{|x| "#{x.chomp}\n"})
|
39
42
|
end
|
40
43
|
|
41
44
|
def save_lines(lines)
|
@@ -43,6 +46,8 @@ module RailsEmbedEditor
|
|
43
46
|
File.open(@filename, 'r') do |f|
|
44
47
|
all_lines = f.readlines
|
45
48
|
end
|
49
|
+
@first_line = 1 if @first_line <= 0
|
50
|
+
@last_line = all_lines.size if @first_line > all_lines.size
|
46
51
|
all_lines = all_lines[0...@first_line-1] + lines + all_lines[@last_line..-1]
|
47
52
|
File.open(@filename, 'w') do |f|
|
48
53
|
all_lines.each do |line|
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_embed_editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timothee Guerin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -100,34 +100,6 @@ dependencies:
|
|
100
100
|
- - ! '>='
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: minitest
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
|
-
type: :development
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - ! '>='
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '0'
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
|
-
name: minitest-reporters
|
119
|
-
requirement: !ruby/object:Gem::Requirement
|
120
|
-
requirements:
|
121
|
-
- - ! '>='
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: '0'
|
124
|
-
type: :development
|
125
|
-
prerelease: false
|
126
|
-
version_requirements: !ruby/object:Gem::Requirement
|
127
|
-
requirements:
|
128
|
-
- - ! '>='
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version: '0'
|
131
103
|
description: A tool that allow to display a embed editor on your page and edit local
|
132
104
|
file(Views, Controller, ...). Details otw
|
133
105
|
email:
|
@@ -184,6 +156,7 @@ files:
|
|
184
156
|
- test/dummy/config/initializers/wrap_parameters.rb
|
185
157
|
- test/dummy/config/locales/en.yml
|
186
158
|
- test/dummy/config/routes.rb
|
159
|
+
- test/dummy/db/development.sqlite3
|
187
160
|
- test/dummy/db/test.sqlite3
|
188
161
|
- test/dummy/log/development.log
|
189
162
|
- test/dummy/log/test.log
|
@@ -251,6 +224,7 @@ test_files:
|
|
251
224
|
- test/dummy/config/locales/en.yml
|
252
225
|
- test/dummy/config/routes.rb
|
253
226
|
- test/dummy/config.ru
|
227
|
+
- test/dummy/db/development.sqlite3
|
254
228
|
- test/dummy/db/test.sqlite3
|
255
229
|
- test/dummy/log/development.log
|
256
230
|
- test/dummy/log/test.log
|