markdown-toolbar 0.0.8 → 0.1.2

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.
data/Changes.markdown ADDED
@@ -0,0 +1,6 @@
1
+ 0.1.2
2
+ =====
3
+ * If textarea is resized the toolbar will also be resized
4
+ * Removed dependency from coffe-script, use only jQuery now
5
+ * Remove dependency on scss, just use pure css
6
+ * Added suite for local testing
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in markdown-toolbar.gemspec
4
2
  gemspec
@@ -1,5 +1,5 @@
1
1
  module Markdown
2
2
  module Toolbar
3
- VERSION = "0.0.8"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -15,10 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
-
19
- s.add_development_dependency 'rails', '~> 3.1.0'
20
- s.add_development_dependency 'jquery-rails'
21
- s.add_development_dependency 'coffee-script'
22
18
 
23
- s.rubyforge_project = s.name
19
+ s.add_development_dependency 'sprockets', '~> 2.0'
20
+ s.add_development_dependency 'sinatra'
21
+
24
22
  end
data/test/server.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'sinatra'
2
+ require 'sprockets'
3
+
4
+ get '/assets/*' do
5
+ environment = Sprockets::Environment.new
6
+ environment.append_path 'vendor/assets/javascripts'
7
+ environment.append_path 'vendor/assets/stylesheets'
8
+ environment.append_path 'vendor/assets/images'
9
+
10
+ environment.context_class.class_eval do
11
+ def asset_path(path, options = {})
12
+ "/assets/#{path}"
13
+ end
14
+ end
15
+
16
+ environment[params[:splat].join('/')].to_s
17
+ end
18
+
19
+
20
+ get '/' do
21
+ erb :index
22
+ end
@@ -0,0 +1,12 @@
1
+ <html>
2
+ <head>
3
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
4
+ <script src="/assets/markdown-toolbar.js" type="text/javascript"></script>
5
+ <link href="/assets/markdown-toolbar.css" media="screen" rel="stylesheet" type="text/css" />
6
+ </head>
7
+
8
+ <body>
9
+ <h1>Markdown Toolbar. v: <%= Markdown::Toolbar::VERSION %><h1>
10
+ <textarea class='markdown-toolbar' style='width:400px;height:300px' onresize='console.log("resized")'></textarea>
11
+ </body>
12
+ </html>
@@ -1,2 +1,2 @@
1
1
  //= require jquery-fieldselection
2
- //= require toolbar
2
+ //= require toolbar.js
@@ -0,0 +1,168 @@
1
+ $(function(){
2
+ $(".markdown-toolbar").each(function(i, textarea){
3
+ new MarkdownToolbar($(textarea));
4
+ });
5
+ });
6
+
7
+ function MarkdownToolbar(textarea){
8
+
9
+ this.init = function(textarea){
10
+ $this = this;
11
+ this.textarea = textarea;
12
+ this.add_toolbar();
13
+ this.fill_buttons();
14
+ this.add_resizer();
15
+ }
16
+
17
+
18
+ this.add_toolbar = function(){
19
+ this.textarea.before("<div class='markdown-toolbar-panel'><div class='mdt_buttons'></div></div>");
20
+ this.panel = this.textarea.prev(".markdown-toolbar-panel");
21
+
22
+ this.textarea.css("margin-top", 0);
23
+ $(["margin-left", "margin-right", "padding-left", "padding-right"]).each(function(i, pos){
24
+ $this.panel.css(pos, $this.textarea.css(pos));
25
+ });
26
+ this.resize_textarea();
27
+ this.textarea.mouseup(function(){
28
+ $this.resize_textarea();
29
+ });
30
+ }
31
+
32
+ this.resize_textarea = function(){
33
+ $this.panel.css("width", $this.textarea.width());
34
+ }
35
+
36
+ this.fill_buttons = function(){
37
+ this.add_button("bold", "Bold", "**", "**");
38
+ this.add_button("italic", "Italic", "*", "*");
39
+ this.add_button("heading_2", "Sub title", "\n## ", " ##\n");
40
+ this.add_button("heading_3", "Sub-sub title", "\n### ", " ###\n" );
41
+ this.add_button("list_bullets", "Bulleted list");
42
+ this.add_button("list_numbers", "Numbered list");
43
+ this.add_button("image", "Insert Image");
44
+ this.add_button("link", "Insert Link");
45
+ }
46
+
47
+ this.add_button = function(button_id, title, tagStart, tagEnd){
48
+ $(".mdt_buttons", this.panel).append("<div class='mdt_button mdt_button_" + button_id + "' title='"+ title + "'></div>");
49
+ $(".mdt_button_" + button_id, this.panel).bind('click', function(event) {
50
+ switch(button_id){
51
+ case "bold":
52
+ case "italic":
53
+ case "heading_2":
54
+ case "heading_3":
55
+ $this.perform_insert_tag(button_id, tagStart, tagEnd);
56
+ break;
57
+
58
+ case "list_numbers":
59
+ case "list_bullets":
60
+ $this.perform_insert_list(button_id)
61
+ break;
62
+
63
+ case "image":
64
+ $this.perform_insert_image();
65
+ break;
66
+ case "link":
67
+ $this.perform_insert_link();
68
+ break;
69
+ }
70
+ });
71
+ }
72
+
73
+
74
+ this.perform_insert_tag = function(button_id, tagStart, tagEnd){
75
+
76
+ var the_text = $this.selected_text();
77
+
78
+ if(the_text.length == 0){
79
+ the_text = "" + button_id + " text";
80
+ }
81
+
82
+ var lines = the_text.split("\n");
83
+ var final_text = "";
84
+
85
+ $(lines).each(function(i, line){
86
+ i++
87
+ final_text += tagStart + line + tagEnd;
88
+ if (i < lines.length){
89
+ final_text += "\n";
90
+ }
91
+ });
92
+
93
+ $this.textarea.replaceSelection( final_text , true );
94
+ $this.textarea.focus();
95
+ }
96
+
97
+ this.selected_text = function(){
98
+ return this.textarea.getSelection().text;
99
+ }
100
+
101
+ this.perform_insert_list = function(button_id) {
102
+ var the_text = this.selected_text();
103
+ if (the_text.length == 0){
104
+ the_text = "Apple\nBananna\nOrange"
105
+ }
106
+
107
+ var lines = the_text.split("\n");
108
+ var final_text = ""
109
+
110
+ tagStart = "-"
111
+ $(lines).each(function(i, line){
112
+ i++
113
+ if (button_id == 'list_numbers'){
114
+ tagStart = "" + i + "." ;
115
+ }
116
+
117
+ final_text += tagStart + " " + line;
118
+ if(i < lines.length){
119
+ final_text += "\n";
120
+ }
121
+ });
122
+
123
+ $this.textarea.replaceSelection( final_text , true );
124
+ $this.textarea.focus();
125
+ }
126
+
127
+
128
+ this.perform_insert_image = function(){
129
+ var the_text = this.selected_text()
130
+ if( the_text.length > 0 && (the_text.substr(0,7) == 'http://' || the_text.substr(0,7) == 'https:/')){
131
+ the_text = "[alt text]("+ the_text +")"
132
+ } else {
133
+ the_text = "![alt text](http://path/to/img.jpg)"
134
+ }
135
+
136
+ $this.textarea.replaceSelection( the_text , true );
137
+ }
138
+
139
+ this.perform_insert_link = function(){
140
+ var the_text = this.selected_text();
141
+ if (the_text.length > 0){
142
+ if (the_text.substr(0,7) == 'http://' || the_text.substr(0,7) == 'https:/'){
143
+ the_text = "["+ the_text +"]("+ the_text + ")"
144
+ } else {
145
+ the_text = "[" + the_text + "](http://...)"
146
+ }
147
+ } else {
148
+ the_text = "[example link](http://example.com/)";
149
+ }
150
+ $this.textarea.replaceSelection( the_text , true );
151
+ }
152
+
153
+ this.add_resizer = function(){
154
+ var do_resize = false;
155
+ var to;
156
+ this.textarea.bind({
157
+ mousedown: function(){
158
+ to = setInterval($this.resize_textarea, 10);
159
+ },
160
+
161
+ mouseup: function(){
162
+ clearInterval(to);
163
+ }
164
+ });
165
+ }
166
+
167
+ this.init(textarea);
168
+ }
@@ -1,11 +1,10 @@
1
1
  .markdown-toolbar-panel {
2
- height:20px;
3
- border:1px solid #aaa;
2
+ height: 20px;
3
+ border: 1px solid #aaa;
4
4
  background: #fafafa;
5
- }
6
- .markdown-toolbar-panel {
7
5
  margin-bottom:0;
8
- border-bottom:0;
6
+ border-bottom:0;
7
+ overflow: hidden;
9
8
  }
10
9
  .markdown-upload-panel {
11
10
  margin-top:0;
@@ -18,6 +17,8 @@
18
17
  display:inline-block;
19
18
  margin-top:2px;
20
19
  margin-bottom:2px;
20
+ height: 20px;
21
+ overflow: hidden;
21
22
  }
22
23
 
23
24
  .mdt_button {
@@ -28,11 +29,19 @@
28
29
  float:left;
29
30
  margin-left:2px;
30
31
  }
32
+
33
+ /* Check this out:
34
+
35
+ <%= self.class.ancestors %>
36
+
37
+ <%= self.public_methods.inspect %>
38
+ */
39
+
31
40
  <% %w{ bold italic strike list_bullets list_numbers heading_2 heading_3 link image}.each_with_index do |button, index| %>
32
41
  .mdt_button_<%= button %> {
33
- background: url( '<%= image_path "text_#{button}.png" %>' );
34
- &:active{
42
+ background: url( <%= asset_path "text_#{button}.png" %>);
43
+ }
44
+ .mdt_button_<%= button %>:active{
35
45
  background-position: 1px 1px;
36
- }
37
46
  }
38
47
  <% end %>
metadata CHANGED
@@ -1,62 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: markdown-toolbar
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
4
5
  prerelease:
5
- version: 0.0.8
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Vitaliy Yanchuk
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-09-23 00:00:00 +03:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: rails
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-11-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sprockets
16
+ requirement: !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
18
+ requirements:
22
19
  - - ~>
23
- - !ruby/object:Gem::Version
24
- version: 3.1.0
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
25
22
  type: :development
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: jquery-rails
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sinatra
32
+ requirement: !ruby/object:Gem::Requirement
31
33
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
36
38
  type: :development
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: coffee-script
40
39
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
42
41
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
47
- type: :development
48
- version_requirements: *id003
49
- description: " Helps with markdown editing "
50
- email:
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ! ' Helps with markdown editing '
47
+ email:
51
48
  - fuksito@gmail.com
52
49
  executables: []
53
-
54
50
  extensions: []
55
-
56
51
  extra_rdoc_files: []
57
-
58
- files:
52
+ files:
59
53
  - .gitignore
54
+ - Changes.markdown
60
55
  - Gemfile
61
56
  - README.markdown
62
57
  - Rakefile
@@ -64,6 +59,8 @@ files:
64
59
  - lib/markdown-toolbar/engine.rb
65
60
  - lib/markdown-toolbar/version.rb
66
61
  - markdown-toolbar.gemspec
62
+ - test/server.rb
63
+ - test/views/index.erb
67
64
  - vendor/.DS_Store
68
65
  - vendor/assets/.DS_Store
69
66
  - vendor/assets/images/.DS_Store
@@ -81,35 +78,32 @@ files:
81
78
  - vendor/assets/images/text_underline.png
82
79
  - vendor/assets/javascripts/jquery-fieldselection.js
83
80
  - vendor/assets/javascripts/markdown-toolbar.js
84
- - vendor/assets/javascripts/toolbar.coffee
85
- - vendor/assets/stylesheets/markdown-toolbar.scss.erb
86
- has_rdoc: true
87
- homepage: ""
81
+ - vendor/assets/javascripts/toolbar.js
82
+ - vendor/assets/stylesheets/markdown-toolbar.css.erb
83
+ homepage: ''
88
84
  licenses: []
89
-
90
85
  post_install_message:
91
86
  rdoc_options: []
92
-
93
- require_paths:
87
+ require_paths:
94
88
  - lib
95
- required_ruby_version: !ruby/object:Gem::Requirement
89
+ required_ruby_version: !ruby/object:Gem::Requirement
96
90
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- version: "0"
101
- required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
96
  none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: "0"
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
107
101
  requirements: []
108
-
109
- rubyforge_project: markdown-toolbar
110
- rubygems_version: 1.6.2
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.24
111
104
  signing_key:
112
105
  specification_version: 3
113
106
  summary: Wrapper to help add markdown syntax into textarea
114
- test_files: []
115
-
107
+ test_files:
108
+ - test/server.rb
109
+ - test/views/index.erb
@@ -1,97 +0,0 @@
1
- $ ->
2
- for textarea in $(".markdown-toolbar")
3
- new MarkdownToolbar $(textarea)
4
-
5
-
6
- class MarkdownToolbar
7
- constructor: (@textarea) ->
8
- this.add_toolbar()
9
-
10
- add_toolbar: ->
11
- @textarea.before "<div class='markdown-toolbar-panel'><div class='mdt_buttons'></div></div>"
12
- @panel = @textarea.prev ".markdown-toolbar-panel"
13
-
14
- @panel.css "width", @textarea.css('width')
15
-
16
- @textarea.css "margin-top", 0
17
-
18
- for pos_type in ["margin", "padding"]
19
- for pos in ['left', 'right']
20
- @panel.css "#{pos_type}-#{pos}", @textarea.css("#{pos_type}-#{pos}")
21
-
22
- this.fill_buttons()
23
-
24
- add_button: (button_id, title, tagStart, tagEnd) ->
25
- $(".mdt_buttons", @panel).append "<div class='mdt_button mdt_button_#{button_id}' title='#{title}'></div>"
26
- $(".mdt_button_#{button_id}", @panel).bind 'click', (event) =>
27
- switch button_id
28
- when "bold", "italic", "heading_2", "heading_3"
29
- this.perform_insert_tag(button_id, tagStart, tagEnd)
30
- when "list_numbers", "list_bullets"
31
- this.perform_insert_list(button_id)
32
- when "image"
33
- this.perform_insert_image()
34
- when "link"
35
- this.perform_insert_link()
36
-
37
- perform_insert_tag: (button_id, tagStart, tagEnd = '') ->
38
- the_text = this.selected_text()
39
- the_text ||= "#{button_id} text"
40
- lines = the_text.split("\n")
41
- final_text = ""
42
- i = 0
43
- for line in lines
44
- i++
45
- final_text += "#{tagStart}#{line}#{tagEnd}"
46
- final_text += "\n" if i < lines.length
47
-
48
- @textarea.replaceSelection( final_text , true )
49
-
50
- perform_insert_list: (button_id) ->
51
- the_text = this.selected_text()
52
- the_text ||= "Apple\nBananna\nOrange"
53
- lines = the_text.split("\n")
54
- final_text = ""
55
- i = 0
56
- tagStart = "-"
57
- for line in lines
58
- i++
59
- tagStart = "#{i}." if button_id == 'list_numbers'
60
- final_text += "#{tagStart} #{line}"
61
- final_text += "\n" if i < lines.length
62
-
63
- @textarea.replaceSelection( final_text , true )
64
-
65
- perform_insert_image: ->
66
- the_text = this.selected_text()
67
- if the_text.length > 0 && (the_text.substr(0,7) == 'http://' || the_text.substr(0,7) == 'https:/')
68
- the_text = "[alt text](#{the_text})"
69
- else
70
- the_text = "![alt text](http://path/to/img.jpg)"
71
-
72
- @textarea.replaceSelection( the_text , true )
73
-
74
- perform_insert_link: ->
75
- the_text = this.selected_text()
76
- if the_text.length > 0
77
- if the_text.substr(0,7) == 'http://' || the_text.substr(0,7) == 'https:/'
78
- the_text = "[#{the_text}](#{the_text})"
79
- else
80
- the_text = "[#{the_text}](http://...)"
81
- else
82
- the_text = "[example link](http://example.com/)"
83
-
84
- @textarea.replaceSelection( the_text , true )
85
-
86
- selected_text: ->
87
- @textarea.getSelection().text
88
-
89
- fill_buttons: ->
90
- this.add_button "bold", "Bold", "**", "**"
91
- this.add_button "italic", "Italic", "*", "*"
92
- this.add_button "heading_2", "Sub title", "\n## ", " ##\n"
93
- this.add_button "heading_3", "Sub-sub title", "\n### ", " ###\n"
94
- this.add_button "list_bullets", "Bulleted list"
95
- this.add_button "list_numbers", "Numbered list"
96
- this.add_button "image", "Insert Image"
97
- this.add_button "link", "Insert Link"