markitup 0.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.
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +34 -0
- data/Rakefile +7 -0
- data/lib/markitup/middleware.rb +79 -0
- data/lib/markitup/railtie.rb +25 -0
- data/lib/markitup/version.rb +3 -0
- data/lib/markitup.rb +3 -0
- data/markitup.gemspec +20 -0
- data/markitup.yml +14 -0
- data/tasks/markitup.rake +30 -0
- data/test/helper.rb +10 -0
- data/test/test_markitup.rb +87 -0
- metadata +81 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Phil Hofmann
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
Markitup
|
2
|
+
========
|
3
|
+
|
4
|
+
Rack middleware to inject CSS & Javascript to turn text areas into
|
5
|
+
rich text editors using Jay Salvat's *MarkItUp!*.
|
6
|
+
|
7
|
+
It effortlessly integrates with Rails.
|
8
|
+
|
9
|
+
Setup
|
10
|
+
-----
|
11
|
+
|
12
|
+
Put this in your Gemfile.
|
13
|
+
|
14
|
+
gem 'markitup'
|
15
|
+
|
16
|
+
And run a couple of rake tasks to get the CSS, Javascript & image
|
17
|
+
assets in place.
|
18
|
+
|
19
|
+
rake markitup:install:base
|
20
|
+
rake markitup:install:markdown
|
21
|
+
|
22
|
+
Configuration
|
23
|
+
-------------
|
24
|
+
|
25
|
+
There is no additional configuration needed. However a config file is
|
26
|
+
created, which can be customized, if you want to have things
|
27
|
+
differently. After the first request, you'll find it here:
|
28
|
+
|
29
|
+
config/markitup.yml
|
30
|
+
|
31
|
+
Links
|
32
|
+
-----
|
33
|
+
|
34
|
+
* http://markitup.jaysalvat.com/home/
|
data/Rakefile
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Markitup
|
4
|
+
class Middleware < Struct.new :app, :options
|
5
|
+
|
6
|
+
def call(env)
|
7
|
+
return app.call(env) unless config['enabled']
|
8
|
+
|
9
|
+
# if env["REQUEST_METHOD"] == "POST"
|
10
|
+
# return render(:markdown, env) if env["PATH_INFO"] =~ /^\/markitup\/markdown/
|
11
|
+
# end
|
12
|
+
|
13
|
+
status, headers, response = app.call(env)
|
14
|
+
return [ status, headers, response ] unless
|
15
|
+
headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/
|
16
|
+
|
17
|
+
body = ""
|
18
|
+
response.each { |part| body << part }
|
19
|
+
return [ status, headers, response ] unless
|
20
|
+
body =~ /#{config['keyword']}/
|
21
|
+
|
22
|
+
index = body.rindex "</head>"
|
23
|
+
if index
|
24
|
+
body.insert index, styles + scripts
|
25
|
+
headers["Content-Length"] = body.length.to_s
|
26
|
+
response = [ body ]
|
27
|
+
end
|
28
|
+
[ status, headers, response ]
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def default_config
|
34
|
+
File.read(File.expand_path('../../../markitup.yml', __FILE__))
|
35
|
+
end
|
36
|
+
|
37
|
+
def config
|
38
|
+
return @config unless @config.nil?
|
39
|
+
conffile = options[:config]
|
40
|
+
::File.open(conffile, 'w') { |out| out.puts default_config } unless ::File.exist?(conffile)
|
41
|
+
@config = ::File.open(conffile) { |yf| YAML::load(yf) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def styles
|
45
|
+
template = '<link rel="stylesheet" type="text/css" href="/stylesheets/%s" />'
|
46
|
+
config['stylesheets'].inject('') { |result, file| result + template % file + "\n" }
|
47
|
+
end
|
48
|
+
|
49
|
+
def scripts
|
50
|
+
template = '<script type="text/javascript" src="/javascripts/%s"></script>'
|
51
|
+
config['javascripts'].inject('') { |result, file| result + template % file + "\n" } + init
|
52
|
+
end
|
53
|
+
|
54
|
+
def init
|
55
|
+
<<-EOB
|
56
|
+
<script type="text/javascript">
|
57
|
+
$(document).ready(function() {
|
58
|
+
$("textarea.#{ config['keyword'] }").markItUp(#{ settings });
|
59
|
+
});
|
60
|
+
</script>
|
61
|
+
EOB
|
62
|
+
end
|
63
|
+
|
64
|
+
def settings
|
65
|
+
return 'mySettings' if config['settings'].nil? or config['settings'].empty?
|
66
|
+
"mySettings, {" + config['settings'].map { |key, val| "'#{key}':'#{val}'" } * ',' + '}'
|
67
|
+
end
|
68
|
+
|
69
|
+
# def render(format, env)
|
70
|
+
# case format
|
71
|
+
# when :markdown
|
72
|
+
# require 'maruku'
|
73
|
+
# body = Maruku.new(env['data']).to_html_document
|
74
|
+
# Rack::Response.new body
|
75
|
+
# end
|
76
|
+
# end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Markitup
|
2
|
+
|
3
|
+
case Rails.version.to_i
|
4
|
+
when 2
|
5
|
+
Rails.configuration.middleware.use Markitup::Middleware,
|
6
|
+
:config => File.expand_path('config/markitup.yml', RAILS_ROOT)
|
7
|
+
|
8
|
+
when 3
|
9
|
+
class Railtie < Rails::Railtie
|
10
|
+
initializer "markitup.insert_middleware" do |app|
|
11
|
+
app.config.middleware.use "Markitup::Middleware",
|
12
|
+
:config => File.expand_path('config/markitup.yml', Rails.root)
|
13
|
+
end
|
14
|
+
|
15
|
+
rake_tasks do
|
16
|
+
load File.expand_path('../../../tasks/markitup.rake', __FILE__)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
else
|
21
|
+
raise "Unknown Rails version"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
data/lib/markitup.rb
ADDED
data/markitup.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "markitup/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "markitup"
|
6
|
+
s.version = Markitup::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Phil Hofmann"]
|
9
|
+
s.email = ["phil@branch14.org"]
|
10
|
+
s.homepage = "http://branch14.org/markitup"
|
11
|
+
s.summary = %q{Rack Middleware to turn text areas into rich text editors}
|
12
|
+
s.description = %q{Rack Middleware to turn text areas into rich text editors}
|
13
|
+
|
14
|
+
# s.rubyforge_project = "markitup"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
data/markitup.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
enabled: true
|
3
|
+
keyword: markItUp
|
4
|
+
javascripts:
|
5
|
+
- markitup/jquery.markitup.js
|
6
|
+
- markitup/sets/default/set.js
|
7
|
+
#- markitup/markdown/set.js
|
8
|
+
stylesheets:
|
9
|
+
- markitup/skins/markitup/style.css
|
10
|
+
- markitup/sets/default/style.css
|
11
|
+
#- markitup/markdown/style.css
|
12
|
+
settings:
|
13
|
+
previewParserPath: /markitup/markdown
|
14
|
+
|
data/tasks/markitup.rake
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
namespace :markitup do
|
2
|
+
namespace :install do
|
3
|
+
task :setup => :environment do
|
4
|
+
ROOT=(defined?(RAILS_ROOT)) ? RAILS_ROOT : Rails.root
|
5
|
+
PRE=File.join('lib', 'markitup')
|
6
|
+
DST=File.join(ROOT, PRE)
|
7
|
+
directory DST
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "fetches basic assets"
|
11
|
+
task :base => :setup do
|
12
|
+
PKG='latest'
|
13
|
+
SRC="http://markitup.jaysalvat.com/downloads/download.php?id=releases/#{PKG}"
|
14
|
+
sh "wget -O #{DST}/#{PKG}.zip '#{SRC}'"
|
15
|
+
sh "unzip -foq #{DST}/#{PKG}.zip -d #{DST}"
|
16
|
+
sh "ln -sf ../../#{PRE}/#{PKG}/markitup public/javascripts"
|
17
|
+
sh "ln -sf ../../#{PRE}/#{PKG}/markitup public/stylesheets"
|
18
|
+
sh "ln -sf ../../#{PRE}/#{PKG}/markitup public/images"
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "fetches markdown assets"
|
22
|
+
task :markdown => :setup do
|
23
|
+
PKG='markdown'
|
24
|
+
SRC="http://markitup.jaysalvat.com/downloads/download.php?id=markupsets/#{PKG}"
|
25
|
+
sh "wget -O #{DST}/#{PKG}.zip '#{SRC}'"
|
26
|
+
sh "unzip -foq #{DST}/#{PKG}.zip -d #{DST}"
|
27
|
+
sh "ln -sf ../../#{PKG} #{DST}/latest/markitup"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
require 'rack/mock'
|
3
|
+
|
4
|
+
class TestMarkitup < Test::Unit::TestCase
|
5
|
+
|
6
|
+
PAYLOAD = 'jquery.markitup.js'
|
7
|
+
|
8
|
+
context "Embedding Markitup" do
|
9
|
+
should "place the payload at the end of the head section of an HTML request" do
|
10
|
+
assert_match EXPECTED_CODE, request.body
|
11
|
+
end
|
12
|
+
|
13
|
+
should "place the payload at the end of the head section of an XHTML request" do
|
14
|
+
response = request(:content_type => 'application/xhtml+xml')
|
15
|
+
assert_match EXPECTED_CODE, response.body
|
16
|
+
end
|
17
|
+
|
18
|
+
should "not place the payload in an HTML request without target" do
|
19
|
+
response = request(:body => [HTML_WITHOUT_TARGET])
|
20
|
+
assert_no_match EXPECTED_CODE, response.body
|
21
|
+
end
|
22
|
+
|
23
|
+
should "not place the konami code in a non HTML request" do
|
24
|
+
response = request(:content_type => 'application/xml', :body => [XML])
|
25
|
+
assert_no_match EXPECTED_CODE, response.body
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
EXPECTED_CODE = /#{PAYLOAD}/m
|
32
|
+
|
33
|
+
HTML_WITH_TARGET = <<-EOHTML
|
34
|
+
<html>
|
35
|
+
<head>
|
36
|
+
<title>Sample Page</title>
|
37
|
+
</head>
|
38
|
+
<body>
|
39
|
+
<h2>Markitup::Middleware Test</h2>
|
40
|
+
<p>This is more test html</p>
|
41
|
+
<textarea class='markItUp'></textarea>
|
42
|
+
</body>
|
43
|
+
</html>
|
44
|
+
EOHTML
|
45
|
+
|
46
|
+
HTML_WITHOUT_TARGET = <<-EOHTML
|
47
|
+
<html>
|
48
|
+
<head>
|
49
|
+
<title>Sample Page</title>
|
50
|
+
</head>
|
51
|
+
<body>
|
52
|
+
<h2>Markitup::Middleware Test</h2>
|
53
|
+
<p>This is more test html</p>
|
54
|
+
<textarea></textarea>
|
55
|
+
</body>
|
56
|
+
</html>
|
57
|
+
EOHTML
|
58
|
+
|
59
|
+
XML = <<-EOXML
|
60
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
61
|
+
<user>
|
62
|
+
<name>Some Name</name>
|
63
|
+
<age>Some Age</age>
|
64
|
+
</user>
|
65
|
+
EOXML
|
66
|
+
|
67
|
+
def request(options={}, path='/')
|
68
|
+
@app = app(options)
|
69
|
+
request = Rack::MockRequest.new(@app).get(path)
|
70
|
+
yield(@app, request) if block_given?
|
71
|
+
request
|
72
|
+
end
|
73
|
+
|
74
|
+
def app(options={})
|
75
|
+
options = options.clone
|
76
|
+
options[:content_type] ||= "text/html"
|
77
|
+
options[:body] ||= [HTML_WITH_TARGET]
|
78
|
+
rack_app = lambda do |env|
|
79
|
+
[ 200,
|
80
|
+
{ 'Content-Type' => options.delete(:content_type) },
|
81
|
+
options.delete(:body) ]
|
82
|
+
end
|
83
|
+
Markitup::Middleware.new(rack_app,
|
84
|
+
:config => File.expand_path('../../markitup.yml', __FILE__))
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markitup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Phil Hofmann
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-11 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Rack Middleware to turn text areas into rich text editors
|
23
|
+
email:
|
24
|
+
- phil@branch14.org
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/markitup.rb
|
38
|
+
- lib/markitup/middleware.rb
|
39
|
+
- lib/markitup/railtie.rb
|
40
|
+
- lib/markitup/version.rb
|
41
|
+
- markitup.gemspec
|
42
|
+
- markitup.yml
|
43
|
+
- tasks/markitup.rake
|
44
|
+
- test/helper.rb
|
45
|
+
- test/test_markitup.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://branch14.org/markitup
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.4.1
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Rack Middleware to turn text areas into rich text editors
|
80
|
+
test_files: []
|
81
|
+
|