markdown_preview 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/.gitignore +48 -0
- data/LICENSE +19 -0
- data/README.md +60 -0
- data/Rakefile +13 -0
- data/app/controllers/markdown_preview_controller.rb +14 -0
- data/config/routes.rb +3 -0
- data/lib/markdown_preview.rb +125 -0
- data/lib/markdown_preview/assets/markdown_preview/markdown_preview.css +69 -0
- data/lib/markdown_preview/assets/markdown_preview/markdown_preview.js +140 -0
- data/lib/markdown_preview/base.rb +29 -0
- data/lib/markdown_preview/configuration.rb +5 -0
- data/lib/markdown_preview/exceptions.rb +14 -0
- data/lib/markdown_preview/helpers.rb +29 -0
- data/lib/tasks/markdown_preview.rake +8 -0
- data/markdown_preview.gemspec +19 -0
- data/test/test_helper.rb +31 -0
- metadata +79 -0
data/.gitignore
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
config/database.yml
|
2
|
+
log/*.log*
|
3
|
+
log/*.pid
|
4
|
+
log/restart.txt
|
5
|
+
tmp/**/*
|
6
|
+
tmp
|
7
|
+
bin/*
|
8
|
+
db/*.sqlite3
|
9
|
+
db/schema.rb
|
10
|
+
db/access_logs
|
11
|
+
*.swp
|
12
|
+
*.swo
|
13
|
+
*.swn
|
14
|
+
coverage
|
15
|
+
public/system
|
16
|
+
public/dgweb
|
17
|
+
public/assets
|
18
|
+
public/css
|
19
|
+
public/jscripts
|
20
|
+
Thumbs.db
|
21
|
+
scratch_directory
|
22
|
+
mkmf.log
|
23
|
+
|
24
|
+
# Other useful tidbit
|
25
|
+
.DS_Store
|
26
|
+
doc/api
|
27
|
+
doc/app
|
28
|
+
doc/plugins
|
29
|
+
coverage
|
30
|
+
*~
|
31
|
+
|
32
|
+
.bundle
|
33
|
+
|
34
|
+
rerun.txt
|
35
|
+
|
36
|
+
db/dumps/**/*
|
37
|
+
|
38
|
+
config/settings/locals.rb
|
39
|
+
|
40
|
+
# For sphinx.
|
41
|
+
db/sphinx/*
|
42
|
+
config/*.sphinx.conf
|
43
|
+
log/searchd.*.pid
|
44
|
+
|
45
|
+
config/initializers/rails_asset_id.rb
|
46
|
+
app/views/dgnetwork/logged_in_index.html_bak.erb
|
47
|
+
app/views/feeds/_feed_item_grouping.html_bak.erb
|
48
|
+
app/views/about_us/contact_us.html copy.erb
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2011 Jeff McFadden
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Markdown Preview for Rails
|
2
|
+
|
3
|
+
This gem gives you instant markdown preview for any textarea you want, anywhere in your application.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
1. Add to your Gemfile:
|
8
|
+
|
9
|
+
`gem 'markdown_preview', :git => 'git://github.com/jeffmcfadden/markdown_preview', :tag => '0.1.1'`
|
10
|
+
|
11
|
+
2. Run the Rake task:
|
12
|
+
|
13
|
+
`rake markdown_preview:install`
|
14
|
+
|
15
|
+
3. Add helper to any controllers you want to use markdown_preview with:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
class MyController < ApplicationController
|
19
|
+
|
20
|
+
uses_markdown_preview
|
21
|
+
```
|
22
|
+
|
23
|
+
4. Add the helper tag to your base layout:
|
24
|
+
|
25
|
+
```html
|
26
|
+
<!-- Note, jQuery include *required* above this line. -->
|
27
|
+
<%= include_markdown_preview_if_needed %>
|
28
|
+
```
|
29
|
+
|
30
|
+
5. (Optional) If you want to override the preprocessor then add the following to `config/initializers/markdown_preview.rb`
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
module MarkdownPreview
|
34
|
+
|
35
|
+
#Write your own preprocessor here if you want to
|
36
|
+
#the md param is the incoming markdown text, before it has been processed
|
37
|
+
def self.preprocess_markdown( md )
|
38
|
+
md
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
6. Add the `markdown_preview` class to any textareas you want to be previewable, and you're good to go!
|
45
|
+
|
46
|
+
```html
|
47
|
+
<textarea class="markdown_preview" id="my_awesome_textarea"></textarea>
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
## Issues
|
52
|
+
|
53
|
+
https://github.com/jeffmcfadden/markdown_preview/issues
|
54
|
+
|
55
|
+
## Credits
|
56
|
+
|
57
|
+
Jeff McFadden
|
58
|
+
|
59
|
+
Desiring God Ministries
|
60
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the markdown_preview gem.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class MarkdownPreviewController < ApplicationController
|
2
|
+
|
3
|
+
def convert
|
4
|
+
markdown = RDiscount.new( MarkdownPreview.preprocess_markdown( params[:markdown_text] ) )
|
5
|
+
|
6
|
+
html = markdown.to_html
|
7
|
+
|
8
|
+
respond_to do |format|
|
9
|
+
format.json { render :json => { :html => html } }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
data/config/routes.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# Require all the necessary files to run MarkdownPreview
|
2
|
+
require 'markdown_preview/base'
|
3
|
+
require 'markdown_preview/exceptions'
|
4
|
+
require 'markdown_preview/configuration'
|
5
|
+
require 'markdown_preview/helpers'
|
6
|
+
|
7
|
+
module MarkdownPreview
|
8
|
+
def self.initialize
|
9
|
+
return if @intialized
|
10
|
+
raise "ActionController is not available yet." unless defined?(ActionController)
|
11
|
+
ActionController::Base.send(:include, MarkdownPreview::Base)
|
12
|
+
ActionController::Base.send(:helper, MarkdownPreview::Helpers)
|
13
|
+
#MarkdownPreview.install_or_update_markdown_preview
|
14
|
+
@intialized = true
|
15
|
+
end
|
16
|
+
|
17
|
+
#Override this is a config somewhere if you want to preprocess your incoming
|
18
|
+
#markdown string. i.e. add a custom tag or something.
|
19
|
+
def self.preprocess_markdown( markdown )
|
20
|
+
markdown
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.install_or_update_markdown_preview
|
24
|
+
require 'fileutils'
|
25
|
+
orig = File.join(File.dirname(__FILE__), 'markdown_preview', 'assets', 'markdown_preview')
|
26
|
+
dest = File.join(Rails.root.to_s, 'public', 'javascripts', 'markdown_preview')
|
27
|
+
markdown_preview_js = File.join(dest, 'markdown_preview.js')
|
28
|
+
|
29
|
+
unless File.exists?(markdown_preview_js) && FileUtils.identical?(File.join(orig, 'markdown_preview.js'), markdown_preview_js)
|
30
|
+
if File.exists?(markdown_preview_js)
|
31
|
+
# upgrade
|
32
|
+
begin
|
33
|
+
puts "Removing directory #{dest}..."
|
34
|
+
FileUtils.rm_rf dest
|
35
|
+
puts "Creating directory #{dest}..."
|
36
|
+
FileUtils.mkdir_p dest
|
37
|
+
puts "Copying MarkdownPreview to #{dest}..."
|
38
|
+
FileUtils.cp_r "#{orig}/.", dest
|
39
|
+
puts "Successfully updated MarkdownPreview."
|
40
|
+
rescue
|
41
|
+
puts 'ERROR: Problem updating MarkdownPreview. Please manually copy '
|
42
|
+
puts orig
|
43
|
+
puts 'to'
|
44
|
+
puts dest
|
45
|
+
end
|
46
|
+
else
|
47
|
+
# install
|
48
|
+
begin
|
49
|
+
puts "Creating directory #{dest}..."
|
50
|
+
FileUtils.mkdir_p dest
|
51
|
+
puts "Copying MarkdownPreview to #{dest}..."
|
52
|
+
FileUtils.cp_r "#{orig}/.", dest
|
53
|
+
puts "Successfully installed MarkdownPreview."
|
54
|
+
rescue
|
55
|
+
puts "ERROR: Problem installing MarkdownPreview. Please manually copy "
|
56
|
+
puts orig
|
57
|
+
puts "to"
|
58
|
+
puts dest
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
orig = File.join(File.dirname(__FILE__), 'markdown_preview', 'assets', 'markdown_preview')
|
66
|
+
dest = File.join(Rails.root.to_s, 'public', 'stylesheets', 'markdown_preview')
|
67
|
+
markdown_preview_css = File.join(dest, 'markdown_preview.css')
|
68
|
+
|
69
|
+
unless File.exists?(markdown_preview_css) && FileUtils.identical?(File.join(orig, 'markdown_preview.css'), markdown_preview_css)
|
70
|
+
if File.exists?(markdown_preview_css)
|
71
|
+
# upgrade
|
72
|
+
begin
|
73
|
+
puts "Removing directory #{dest}..."
|
74
|
+
FileUtils.rm_rf dest
|
75
|
+
puts "Creating directory #{dest}..."
|
76
|
+
FileUtils.mkdir_p dest
|
77
|
+
puts "Copying MarkdownPreview to #{dest}..."
|
78
|
+
FileUtils.cp_r "#{orig}/.", dest
|
79
|
+
puts "Successfully updated MarkdownPreview."
|
80
|
+
rescue
|
81
|
+
puts 'ERROR: Problem updating MarkdownPreview. Please manually copy '
|
82
|
+
puts orig
|
83
|
+
puts 'to'
|
84
|
+
puts dest
|
85
|
+
end
|
86
|
+
else
|
87
|
+
# install
|
88
|
+
begin
|
89
|
+
puts "Creating directory #{dest}..."
|
90
|
+
FileUtils.mkdir_p dest
|
91
|
+
puts "Copying MarkdownPreview to #{dest}..."
|
92
|
+
FileUtils.cp_r "#{orig}/.", dest
|
93
|
+
puts "Successfully installed MarkdownPreview."
|
94
|
+
rescue
|
95
|
+
puts "ERROR: Problem installing MarkdownPreview. Please manually copy "
|
96
|
+
puts orig
|
97
|
+
puts "to"
|
98
|
+
puts dest
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
module Base
|
109
|
+
end
|
110
|
+
|
111
|
+
class Engine < Rails::Engine
|
112
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
113
|
+
|
114
|
+
def self.activate
|
115
|
+
#Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*.rb")) do |c|
|
116
|
+
# Rails.env.production? ? require(c) : load(c)
|
117
|
+
#end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
config.to_prepare &method(:activate).to_proc
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
MarkdownPreview.initialize
|
@@ -0,0 +1,69 @@
|
|
1
|
+
.markdown_wrap{
|
2
|
+
border: 2px solid #CCC;
|
3
|
+
-webkit-border-radius: 3px;
|
4
|
+
-moz-border-radius: 3px;
|
5
|
+
border-radius: 3px;
|
6
|
+
}
|
7
|
+
|
8
|
+
.markdown_wrap textarea{
|
9
|
+
width: 100%;
|
10
|
+
}
|
11
|
+
|
12
|
+
.markdown_wrap_menu{
|
13
|
+
height: 1.5em;
|
14
|
+
background-color: #CCC;
|
15
|
+
margin: 0px;
|
16
|
+
padding: 2px;
|
17
|
+
}
|
18
|
+
|
19
|
+
.markdown_wrap_help{
|
20
|
+
background-color: #AAA;
|
21
|
+
padding: 3px;
|
22
|
+
display: none;
|
23
|
+
}
|
24
|
+
|
25
|
+
.markdown_wrap_content{
|
26
|
+
padding: 2px;
|
27
|
+
}
|
28
|
+
|
29
|
+
.markdown_wrap_menu div{
|
30
|
+
font-size: 80%;
|
31
|
+
color: #222;
|
32
|
+
|
33
|
+
float: left;
|
34
|
+
margin-right: 1em;
|
35
|
+
border: 1px solid #888;
|
36
|
+
padding: 2px;
|
37
|
+
-webkit-border-radius: 2em;
|
38
|
+
-moz-border-radius: 2em;
|
39
|
+
border-radius: 2em;
|
40
|
+
|
41
|
+
padding-left: 10px;
|
42
|
+
padding-right: 10px;
|
43
|
+
text-align: center;
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
.markdown_wrap_menu .markdown_wrap_menu_help{
|
48
|
+
float: right;
|
49
|
+
}
|
50
|
+
|
51
|
+
.markdown_wrap.editing .markdown_wrap_menu_preview, .markdown_wrap.previewing .markdown_wrap_menu_edit, .markdown_wrap_menu_help{
|
52
|
+
background-color: none;
|
53
|
+
border: 1px solid #888;
|
54
|
+
}
|
55
|
+
|
56
|
+
.markdown_wrap.editing .markdown_wrap_menu_edit, .markdown_wrap.previewing .markdown_wrap_menu_preview, .markdown_wrap.helping .markdown_wrap_menu_help{
|
57
|
+
background-color: #EEE;
|
58
|
+
border-top: 1px solid #444;
|
59
|
+
border-bottom: 1px solid #BBB;
|
60
|
+
}
|
61
|
+
|
62
|
+
.markdown_wrap_menu_edit, .markdown_wrap_menu_preview, .markdown_wrap_menu_help{
|
63
|
+
cursor: pointer;
|
64
|
+
}
|
65
|
+
|
66
|
+
.markdown_wrap_preview{
|
67
|
+
display: none;
|
68
|
+
}
|
69
|
+
|
@@ -0,0 +1,140 @@
|
|
1
|
+
(function( $ ){
|
2
|
+
|
3
|
+
$.fn.markdownPreview = function( type ) {
|
4
|
+
|
5
|
+
return this.each(function() {
|
6
|
+
|
7
|
+
var $this = $(this);
|
8
|
+
|
9
|
+
$this.wrap( '<div class="markdown_wrap editing"></div>' );
|
10
|
+
|
11
|
+
$this.before( '<div class="markdown_wrap_menu"><div class="markdown_wrap_menu_help">Help</div><div class="markdown_wrap_menu_edit">Write</div><div class="markdown_wrap_menu_preview">Preview</div></div>' );
|
12
|
+
|
13
|
+
var help_text = [
|
14
|
+
'<div class="content cheatsheet">',
|
15
|
+
'<h2>Markdown Cheat Sheet</h2>',
|
16
|
+
'<div class="cheatsheet-content">',
|
17
|
+
'<div class="mod">',
|
18
|
+
'<div class="col">',
|
19
|
+
'<h3>Format Text</h3>',
|
20
|
+
'<p>Headers</p>',
|
21
|
+
'<pre># This is an <h1> tag',
|
22
|
+
'## This is an <h2> tag',
|
23
|
+
'###### This is an <h6> tag</pre>',
|
24
|
+
' <p>Text styles</p>',
|
25
|
+
' <pre>*This text will be italic*',
|
26
|
+
'_This will also be italic_',
|
27
|
+
'**This text will be bold**',
|
28
|
+
'__This will also be bold__',
|
29
|
+
'',
|
30
|
+
'*You **can** combine them*',
|
31
|
+
'</pre>',
|
32
|
+
'</div>',
|
33
|
+
'<div class="col">',
|
34
|
+
'<h3>Lists</h3>',
|
35
|
+
'<p>Unordered</p>',
|
36
|
+
'<pre>* Item 1',
|
37
|
+
'* Item 2',
|
38
|
+
' * Item 2a',
|
39
|
+
' * Item 2b</pre>',
|
40
|
+
' <p>Ordered</p>',
|
41
|
+
' <pre>1. Item 1',
|
42
|
+
'2. Item 2',
|
43
|
+
'3. Item 3',
|
44
|
+
' * Item 3a',
|
45
|
+
' * Item 3b</pre>',
|
46
|
+
'</div>',
|
47
|
+
'<div class="col">',
|
48
|
+
'<h3>Miscellaneous</h3>',
|
49
|
+
'<p>Images</p>',
|
50
|
+
'<pre>',
|
51
|
+
'Format: ',
|
52
|
+
'</pre>',
|
53
|
+
'<p>Links</p>',
|
54
|
+
'<pre>http://github.com - automatic!',
|
55
|
+
'[GitHub](http://github.com)</pre>',
|
56
|
+
'<p>Blockquotes</p>',
|
57
|
+
'<pre>As Kanye West said:',
|
58
|
+
'> We\'re living the future so',
|
59
|
+
'> the present is our past.',
|
60
|
+
'</pre>',
|
61
|
+
'</div>',
|
62
|
+
'</div>',
|
63
|
+
'<div class="rule"></div>',
|
64
|
+
'</div>',
|
65
|
+
'</div>' ].join( "\n" );
|
66
|
+
|
67
|
+
|
68
|
+
$this.before( '<div class="markdown_wrap_help">' + help_text + '</div>' );
|
69
|
+
|
70
|
+
$this.wrap( '<div class="markdown_wrap_content"></div>' );
|
71
|
+
$this.after( '<div class="markdown_wrap_preview"></div>' );
|
72
|
+
|
73
|
+
$this.wrap( '<div class="markdown_wrap_editor"></div>' );
|
74
|
+
|
75
|
+
/*
|
76
|
+
if ( !type || type == 'width' ) {
|
77
|
+
$this.width( $this.width() );
|
78
|
+
}
|
79
|
+
|
80
|
+
if ( !type || type == 'height' ) {
|
81
|
+
$this.height( $this.height() );
|
82
|
+
}*/
|
83
|
+
|
84
|
+
});
|
85
|
+
|
86
|
+
};
|
87
|
+
|
88
|
+
$( '.markdown_wrap_menu_help' ).live( 'click', function(){
|
89
|
+
//console.log( 'Clicked Help' );
|
90
|
+
$( this ).closest( '.markdown_wrap' ).toggleClass( 'helping' );
|
91
|
+
|
92
|
+
$( this ).closest( '.markdown_wrap' ).find( '.markdown_wrap_help' ).slideToggle( 'fast' );
|
93
|
+
});
|
94
|
+
|
95
|
+
$( '.markdown_wrap_menu_edit' ).live( 'click', function(){
|
96
|
+
//console.log( 'Clicked Edit' );
|
97
|
+
$( this ).closest( '.markdown_wrap' ).removeClass( 'previewing' ).addClass( 'editing' );
|
98
|
+
|
99
|
+
$( this ).closest( '.markdown_wrap' ).find( '.markdown_wrap_preview' ).hide();
|
100
|
+
$( this ).closest( '.markdown_wrap' ).find( '.markdown_wrap_editor' ).show();
|
101
|
+
});
|
102
|
+
|
103
|
+
$( '.markdown_wrap_menu_preview' ).live( 'click', function(){
|
104
|
+
//console.log( 'Clicked Preview' );
|
105
|
+
$( this ).closest( '.markdown_wrap' ).removeClass( 'editing' ).addClass( 'previewing' );
|
106
|
+
|
107
|
+
var editor = $( this ).closest( '.markdown_wrap' ).find( '.markdown_wrap_editor' );
|
108
|
+
var preview = $( this ).closest( '.markdown_wrap' ).find( '.markdown_wrap_preview' );
|
109
|
+
|
110
|
+
preview.html( 'Loading...' );
|
111
|
+
|
112
|
+
editor.hide();
|
113
|
+
preview.show();
|
114
|
+
|
115
|
+
var editor_content = editor.find( 'textarea' ).val();
|
116
|
+
|
117
|
+
$.ajax({
|
118
|
+
type: 'POST',
|
119
|
+
url: '/markdown_preview/convert',
|
120
|
+
data: 'format=json&markdown_text=' + editor_content,
|
121
|
+
success: function( data, textStatus, jqXHR ){
|
122
|
+
preview.html( data['html'] );
|
123
|
+
},
|
124
|
+
error: function(jqXHR, textStatus, errorThrown){
|
125
|
+
//console.log( "ERROR" );
|
126
|
+
//console.log( jqXHR );
|
127
|
+
//console.log( textStatus );
|
128
|
+
//console.log( errorThrown );
|
129
|
+
},
|
130
|
+
dataType: 'text json'
|
131
|
+
});
|
132
|
+
|
133
|
+
});
|
134
|
+
})( jQuery );
|
135
|
+
|
136
|
+
|
137
|
+
$( document ).ready( function(){
|
138
|
+
$( '.markdown_preview' ).markdownPreview();
|
139
|
+
});
|
140
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MarkdownPreview
|
2
|
+
# The base module we include into ActionController::Base
|
3
|
+
module Base
|
4
|
+
# When this module is included, extend it with the available class methods
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
# The controller declaration to enable markdown_preview certain actions.
|
11
|
+
# Takes options hash, raw_options string, and any normal params you
|
12
|
+
# can send to a before_filter (only, except etc)
|
13
|
+
def uses_markdown_preview(options = {})
|
14
|
+
configuration = MarkdownPreview::Configuration.new(options.delete(:options), options.delete(:raw_options))
|
15
|
+
|
16
|
+
# Set instance vars in the current class
|
17
|
+
proc = Proc.new do |c|
|
18
|
+
configurations = c.instance_variable_get(:@markdown_preview_configurations) || []
|
19
|
+
configurations << configuration
|
20
|
+
c.instance_variable_set(:@markdown_preview_configurations, configurations)
|
21
|
+
c.instance_variable_set(:@uses_markdown_preview, true)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Run the above proc before each page load this method is declared in
|
25
|
+
before_filter(proc, options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MarkdownPreview
|
2
|
+
# Setup a couple of Exception classes that we use later on
|
3
|
+
class MarkdownPreviewInvalidOption < Exception
|
4
|
+
def self.invalid_option(option)
|
5
|
+
new "Invalid option #{option} passed to MarkdownPreview"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class MarkdownPreviewInvalidOptionType < Exception
|
10
|
+
def self.invalid_type_of(value, parameters={})
|
11
|
+
new "Invalid value of type #{value.class} passed for MarkdownPreview option #{parameters[:for].to_s}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MarkdownPreview
|
2
|
+
# The helper module we include into ActionController::Base
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
# Has uses_markdown_preview method been declared in the controller for this page?
|
6
|
+
def using_markdown_preview?
|
7
|
+
!@uses_markdown_preview.blank?
|
8
|
+
end
|
9
|
+
|
10
|
+
# Form a JS include tag for the MarkdownPreview JS src for inclusion in the <head>
|
11
|
+
def include_markdown_preview_js
|
12
|
+
#javascript_include_tag (Rails.env.to_s == 'development' ? "markdown_preview/markdown_preview" : "markdown_preview/markdown_preview.min")
|
13
|
+
javascript_include_tag (Rails.env.to_s == 'development' ? "markdown_preview/markdown_preview" : "markdown_preview/markdown_preview")
|
14
|
+
end
|
15
|
+
|
16
|
+
# Form a JS include tag for the MarkdownPreview JS src for inclusion in the <head>
|
17
|
+
def include_markdown_preview_css
|
18
|
+
stylesheet_link_tag( "markdown_preview/markdown_preview" )
|
19
|
+
end
|
20
|
+
|
21
|
+
# Form a JS include tag for the MarkdownPreview JS src, and form the raw JS and wrap
|
22
|
+
# in in a <script> tag for inclusion in the <head> for inclusion in the <head>
|
23
|
+
def include_markdown_preview_if_needed(options = {}, raw_options = nil)
|
24
|
+
if using_markdown_preview?
|
25
|
+
include_markdown_preview_js + include_markdown_preview_css
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.platform = Gem::Platform::RUBY
|
3
|
+
s.name = 'markdown_preview'
|
4
|
+
s.version = '0.1.2'
|
5
|
+
s.authors = ["Jeff McFadden"]
|
6
|
+
s.email = "jeff.mcfadden@gmail.com"
|
7
|
+
s.homepage = "http://github.com/jeffmcfadden/markdown_preview"
|
8
|
+
s.summary = "Markdown Preview of any textarea editor for your rails applications."
|
9
|
+
s.description = "Gem that allows easy preview of your textarea content as markdown."
|
10
|
+
|
11
|
+
s.required_ruby_version = '>= 1.9.2'
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.require_path = 'lib'
|
16
|
+
s.requirements << 'none'
|
17
|
+
|
18
|
+
s.add_dependency('rdiscount')
|
19
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../../test/test_helper")
|
2
|
+
|
3
|
+
# Use non-default action names to get around possible authentication
|
4
|
+
# filters to ensure the tests work in most cases
|
5
|
+
module TinyMCEActions
|
6
|
+
def new_page
|
7
|
+
render :text => 'Hello'
|
8
|
+
end
|
9
|
+
def edit_page
|
10
|
+
render :text => 'Hello'
|
11
|
+
end
|
12
|
+
def show_page
|
13
|
+
render :text => 'Hello'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class TestController
|
18
|
+
def self.helper(s) s; end
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_constant(constant, value)
|
22
|
+
if respond_to?(:silence_warnings)
|
23
|
+
silence_warnings do
|
24
|
+
Object.send(:remove_const, constant) if Object.const_defined?(constant)
|
25
|
+
Object.const_set(constant, value)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
Object.send(:remove_const, constant) if Object.const_defined?(constant)
|
29
|
+
Object.const_set(constant, value)
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markdown_preview
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeff McFadden
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-19 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rdiscount
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: Gem that allows easy preview of your textarea content as markdown.
|
27
|
+
email: jeff.mcfadden@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files: []
|
33
|
+
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- app/controllers/markdown_preview_controller.rb
|
40
|
+
- config/routes.rb
|
41
|
+
- lib/markdown_preview.rb
|
42
|
+
- lib/markdown_preview/assets/markdown_preview/markdown_preview.css
|
43
|
+
- lib/markdown_preview/assets/markdown_preview/markdown_preview.js
|
44
|
+
- lib/markdown_preview/base.rb
|
45
|
+
- lib/markdown_preview/configuration.rb
|
46
|
+
- lib/markdown_preview/exceptions.rb
|
47
|
+
- lib/markdown_preview/helpers.rb
|
48
|
+
- lib/tasks/markdown_preview.rake
|
49
|
+
- markdown_preview.gemspec
|
50
|
+
- test/test_helper.rb
|
51
|
+
homepage: http://github.com/jeffmcfadden/markdown_preview
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.9.2
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
requirements:
|
72
|
+
- none
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Markdown Preview of any textarea editor for your rails applications.
|
78
|
+
test_files:
|
79
|
+
- test/test_helper.rb
|