code_filtered 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/Manifest.txt +7 -0
- data/README.txt +64 -0
- data/Rakefile +17 -0
- data/bin/code_filtered +0 -0
- data/lib/code_filtered.rb +53 -0
- data/test/test_code_filtered.rb +0 -0
- metadata +70 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
= CodeFiltered
|
2
|
+
|
3
|
+
http://rubyforge.org/projects/sintaxi/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Filters from your choice of Markdown, Textile or Plain HTML into
|
8
|
+
HTML and gives appropriate markup for syntax highlighting on code.
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
* Formats Textile or Markdown
|
13
|
+
* Applies markup to code for syntax highlighting.
|
14
|
+
* requires a filter(string) column
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
In any model specify what columns to filter and how it should
|
19
|
+
be filtered using a 'filter' column with a value of Markdown,
|
20
|
+
Textile or Plain HTML.
|
21
|
+
|
22
|
+
code_filtered :body, :excerpt
|
23
|
+
|
24
|
+
In this case the filtered(html) data will be saved to body_html
|
25
|
+
and excerpt_html (be sure those columns exist in your database.
|
26
|
+
|
27
|
+
All instances of <code></code> will have markup for syntax
|
28
|
+
highlighting. Specify your markup language eg. <code:ruby></code>
|
29
|
+
or <code:javascript></code>
|
30
|
+
|
31
|
+
== REQUIREMENTS:
|
32
|
+
|
33
|
+
* RedCloth
|
34
|
+
* BlueCloth
|
35
|
+
* CodeRay
|
36
|
+
|
37
|
+
== INSTALL:
|
38
|
+
|
39
|
+
* sudo gem install code_filtered
|
40
|
+
|
41
|
+
== LICENSE:
|
42
|
+
|
43
|
+
(The MIT License)
|
44
|
+
|
45
|
+
Copyright (c) Brock Whitten 2008
|
46
|
+
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
48
|
+
a copy of this software and associated documentation files (the
|
49
|
+
'Software'), to deal in the Software without restriction, including
|
50
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
51
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
52
|
+
permit persons to whom the Software is furnished to do so, subject to
|
53
|
+
the following conditions:
|
54
|
+
|
55
|
+
The above copyright notice and this permission notice shall be
|
56
|
+
included in all copies or substantial portions of the Software.
|
57
|
+
|
58
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
59
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
60
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
61
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
62
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
63
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
64
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/code_filtered.rb'
|
6
|
+
|
7
|
+
Hoe.new('code_filtered', CodeFiltered::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'sintaxi'
|
9
|
+
p.author = 'Brock Whitten'
|
10
|
+
p.email = 'brock@sintaxi.com'
|
11
|
+
p.summary = 'filter Markdown or Textile to html with code syntax highlighting'
|
12
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
13
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
# vim: syntax=Ruby
|
data/bin/code_filtered
ADDED
File without changes
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'RedCloth'
|
2
|
+
require 'BlueCloth'
|
3
|
+
require 'coderay'
|
4
|
+
|
5
|
+
class CodeFiltered
|
6
|
+
VERSION = '0.1.1'
|
7
|
+
end
|
8
|
+
|
9
|
+
module Sintaxi
|
10
|
+
module CodeFiltered
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.extend ActMethods
|
14
|
+
end
|
15
|
+
|
16
|
+
module ActMethods
|
17
|
+
def filtered_light(*columns)
|
18
|
+
unless included_modules.include? InstanceMethods
|
19
|
+
include InstanceMethods
|
20
|
+
class_inheritable_accessor :unfiltered
|
21
|
+
before_save :filter_columns
|
22
|
+
end
|
23
|
+
self.unfiltered ||= columns ||= []
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module InstanceMethods
|
28
|
+
def filter_columns
|
29
|
+
unfiltered.each do |column|
|
30
|
+
send "#{column}_html=", sanitize(send(column).to_s.dup, self.filter)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def sanitize(text, filter="Plain HTML")
|
35
|
+
textilized = case filter
|
36
|
+
when "Markdown" then sanitize_code(BlueCloth.new(text)).to_html
|
37
|
+
when "Textile" then sanitize_code(RedCloth.new(text).to_html)
|
38
|
+
else sanitize_code(text.dup)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def sanitize_code(text)
|
43
|
+
text.scan(/(<code\:([a-z].+?)>(.+?)<\/code>)/m).each do |match|
|
44
|
+
text.gsub!(match[0],CodeRay.scan(match[2], match[1].to_sym).div(:css => :class))
|
45
|
+
end
|
46
|
+
text
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
ActiveRecord::Base.send :include, Sintaxi::CodeFiltered if defined?(ActiveRecord::Base)
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: code_filtered
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brock Whitten
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-05 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.0
|
23
|
+
version:
|
24
|
+
description: "== DESCRIPTION: Filters from your choice of Markdown, Textile or Plain HTML into HTML and gives appropriate markup for syntax highlighting on code. == FEATURES/PROBLEMS: * Formats Textile or Markdown * Applies markup to code for syntax highlighting. * requires a filter(string) column"
|
25
|
+
email: brock@sintaxi.com
|
26
|
+
executables:
|
27
|
+
- code_filtered
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- README.txt
|
38
|
+
- Rakefile
|
39
|
+
- bin/code_filtered
|
40
|
+
- lib/code_filtered.rb
|
41
|
+
- test/test_code_filtered.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage:
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --main
|
47
|
+
- README.txt
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project: sintaxi
|
65
|
+
rubygems_version: 1.0.1
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: filter Markdown or Textile to html with code syntax highlighting
|
69
|
+
test_files:
|
70
|
+
- test/test_code_filtered.rb
|