tm_syntax_highlighting 0.0.0
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/MIT-LICENSE +20 -0
- data/README +68 -0
- data/Rakefile +45 -0
- data/VERSION +2 -0
- data/generators/syntax_css/syntax_css_generator.rb +49 -0
- data/generators/syntax_css/templates/.gitignore +0 -0
- data/init.rb +9 -0
- data/install.rb +1 -0
- data/lib/tm_syntax_highlighting.rb +81 -0
- data/test/tm_syntax_highlighting_test.rb +8 -0
- data/uninstall.rb +1 -0
- metadata +74 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
TmSyntaxHighlighting
|
2
|
+
====================
|
3
|
+
** NOTE: You must install ultraviolet *before* installing this plugin. Follow the instructions below.
|
4
|
+
|
5
|
+
This plugin allows you to add TextMate themed syntax highlighting to your views.
|
6
|
+
|
7
|
+
It requires the Ultraviolet gem, which requires TextPow, which requires oniguruma (both the gem and the system library).
|
8
|
+
|
9
|
+
Oniguruma is a regular expression library used by TextPow in order to properly parse TextMate syntax/language files.
|
10
|
+
It's relatively easy to install, here is the URL for the library:
|
11
|
+
http://www.geocities.jp/kosako3/oniguruma/
|
12
|
+
|
13
|
+
Then you need to do
|
14
|
+
$ gem install ultraviolet
|
15
|
+
which should install ultraviolet, textpow, and oniguruma.
|
16
|
+
|
17
|
+
Lastly, in order for this plugin to properly copy the syntax CSS files from ultraviolet, ultraviolet must already be installed. In other words, you need to install ultraviolet before installing this plugin.
|
18
|
+
|
19
|
+
The plugin comes with a generator for the stylesheets for the different themes.
|
20
|
+
|
21
|
+
# to see a list of themes
|
22
|
+
$ script/generate syntax_css list
|
23
|
+
|
24
|
+
# to copy all the themes to public/stylesheets/syntax
|
25
|
+
$ script/generate syntax_css all
|
26
|
+
|
27
|
+
# to copy a single theme to public/stylesheets/syntax
|
28
|
+
$ script/generate syntax_css theme_name
|
29
|
+
|
30
|
+
Example
|
31
|
+
=======
|
32
|
+
|
33
|
+
The plugin adds 2 view helper methods: code and syntax_css
|
34
|
+
|
35
|
+
code (helper method) usage
|
36
|
+
==========================
|
37
|
+
|
38
|
+
code(some_ruby_code, :theme => "twilight", :lang => "ruby", :line_numbers => true)
|
39
|
+
|
40
|
+
lang and line_numbers are optional. lang will default to plain_text and line_numbers will default to true.
|
41
|
+
It is *HIGHLY* recommended that you fragment_cache or some other type of caching for code fragments (TextPow and/or Ultraviolet have some speed issues).
|
42
|
+
|
43
|
+
theme can be an array, and one will be chosen at random.
|
44
|
+
|
45
|
+
you can set defaults in an initializer:
|
46
|
+
|
47
|
+
# config/initializers/tm_syntax_config.rb
|
48
|
+
TmSyntaxHighlighting.defaults = {:theme => "sunburst", :line_numbers => true, :lang => "ruby"}
|
49
|
+
|
50
|
+
again, theme can be an array and will be chosen at random.
|
51
|
+
|
52
|
+
|
53
|
+
syntax_css (helper_method) usage
|
54
|
+
================================
|
55
|
+
lastly, the syntax_css method will include the stylesheet tags for the themes
|
56
|
+
|
57
|
+
you can call it with a theme name
|
58
|
+
|
59
|
+
syntax_css("twilight")
|
60
|
+
|
61
|
+
or if you call it with no options, it will include all the css files for the themes used in this request
|
62
|
+
|
63
|
+
code(some_ruby_code, :theme => "twilight")
|
64
|
+
code(some_more_ruby_code, :theme => "sunburst")
|
65
|
+
...
|
66
|
+
syntax_css # yields stylesheet tags for both twilight and sunburst
|
67
|
+
|
68
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'uv'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |s|
|
9
|
+
s.name = "tm_syntax_highlighting"
|
10
|
+
#s.executables = "tm_syntax_highlighting"
|
11
|
+
s.summary = "a gem to get syntaxhilight via ultraviolet"
|
12
|
+
s.description = "a gem to get syntaxhilight via ultraviolet"
|
13
|
+
s.email = "seivan@kth.se"
|
14
|
+
s.homepage = "http://github.com/seivan"
|
15
|
+
#s.rubyforge_project = 'pickles'
|
16
|
+
s.authors = ["Seivan Heidari"]
|
17
|
+
#s.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore']
|
18
|
+
s.add_development_dependency ["ultraviolet"]
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
end
|
21
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
22
|
+
#rubyforge.doc_task = "yardoc"
|
23
|
+
end
|
24
|
+
rescue LoadError
|
25
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Default: run unit tests.'
|
29
|
+
task :default => :test
|
30
|
+
|
31
|
+
desc 'Test the tm_syntax_highlighting plugin.'
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
33
|
+
t.libs << 'lib'
|
34
|
+
t.pattern = 'test/**/*_test.rb'
|
35
|
+
t.verbose = true
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Generate documentation for the tm_syntax_highlighting plugin.'
|
39
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = 'TmSyntaxHighlighting'
|
42
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
43
|
+
rdoc.rdoc_files.include('README')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
class SyntaxCssGenerator < Rails::Generator::Base
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
# This whole copy CSS files to the tamplates folder isn't very clean
|
5
|
+
# generator library doesn't let me specify an absolute path for m.file so this is a compromise
|
6
|
+
# FIXME: make this cleaner
|
7
|
+
theme = args[0]
|
8
|
+
|
9
|
+
themes = Uv.themes
|
10
|
+
|
11
|
+
if theme == "all"
|
12
|
+
m.directory("public/stylesheets/syntax")
|
13
|
+
copy_theme_from_uv(*themes)
|
14
|
+
themes.each do |css|
|
15
|
+
m.file("/#{css}.css", "public/stylesheets/syntax/#{css}.css")
|
16
|
+
end
|
17
|
+
elsif theme == "list"
|
18
|
+
puts themes.sort.join("\n")
|
19
|
+
else
|
20
|
+
css = themes.detect do |s|
|
21
|
+
s.downcase.strip == theme.downcase.strip
|
22
|
+
end
|
23
|
+
|
24
|
+
if css
|
25
|
+
m.directory("public/stylesheets/syntax")
|
26
|
+
m.file("#{css}.css", "public/stylesheets/syntax/#{css}.css")
|
27
|
+
else
|
28
|
+
usage_message
|
29
|
+
puts "Could not find theme named #{theme}."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
def banner
|
37
|
+
puts "Copies Syntax CSS files to public/stylesheets/syntax/\n\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
def usage_message
|
41
|
+
puts "Usage: #{$0} syntax_css [all | list | theme_name]"
|
42
|
+
end
|
43
|
+
|
44
|
+
def copy_theme_from_uv(*args)
|
45
|
+
args.each do |theme|
|
46
|
+
FileUtils.cp(File.join(Uv.path, "render", "xhtml", "files", "css", "#{theme}.css"), source_path("/"))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
File without changes
|
data/init.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'uv'
|
3
|
+
|
4
|
+
# takes about a second to this, if we don't do it now, then the first call to highlight will take a little longer
|
5
|
+
Uv.init_syntaxes
|
6
|
+
|
7
|
+
ActionView::Base.send(:include, TmSyntaxHighlighting::Helper)
|
8
|
+
ActionController::Base.send(:extend, TmSyntaxHighlighting::Controller)
|
9
|
+
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
puts IO.read(File.join(File.dirname(__FILE__), 'README'))
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module TmSyntaxHighlighting
|
2
|
+
module Helper
|
3
|
+
def code(code, options = {})
|
4
|
+
options = TmSyntaxHighlighting.defaults.merge_with(options)
|
5
|
+
TmSyntaxHighlighting.defaults[:current_themes] << options[:theme]
|
6
|
+
options[:lang] = "plain_text" unless Uv.syntaxes.include?(options[:lang])
|
7
|
+
Uv.parse(code, "xhtml", options[:lang], options[:line_numbers], options[:theme])
|
8
|
+
end
|
9
|
+
|
10
|
+
def syntax_css(theme = nil)
|
11
|
+
themes = [theme || TmSyntaxHighlighting.defaults.options[:theme]].flatten
|
12
|
+
themes = (themes & TmSyntaxHighlighting.defaults[:current_themes]) if theme.nil? && TmSyntaxHighlighting.defaults[:current_themes]
|
13
|
+
themes.uniq.collect do |theme|
|
14
|
+
stylesheet_link_tag "syntax/#{theme}"
|
15
|
+
end.join("\n")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Controller
|
20
|
+
def self.extended(base)
|
21
|
+
base.after_filter :reset_syntax_css_includes
|
22
|
+
base.send(:include, InstanceMethods)
|
23
|
+
TmSyntaxHighlighting.defaults.reset_current_themes
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods
|
27
|
+
end
|
28
|
+
|
29
|
+
module InstanceMethods
|
30
|
+
def reset_syntax_css_includes
|
31
|
+
TmSyntaxHighlighting.defaults.reset_current_themes
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.defaults
|
37
|
+
Config
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.defaults=(options_hash)
|
41
|
+
options_hash.each do |key, value|
|
42
|
+
self.defaults.send("#{key}=", value)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Config
|
47
|
+
@@attributes = [:theme, :lang, :line_numbers, :current_themes]
|
48
|
+
cattr_accessor @@attributes
|
49
|
+
|
50
|
+
self.line_numbers = true
|
51
|
+
class << self
|
52
|
+
def [](key)
|
53
|
+
self.send(key)
|
54
|
+
end
|
55
|
+
|
56
|
+
def []=(key, value)
|
57
|
+
self.send("#{key}=", value)
|
58
|
+
end
|
59
|
+
|
60
|
+
def options
|
61
|
+
opts = {}
|
62
|
+
@@attributes.each do |attribute|
|
63
|
+
opts[attribute] = self.send(attribute)
|
64
|
+
end
|
65
|
+
opts
|
66
|
+
end
|
67
|
+
|
68
|
+
def merge_with(opts)
|
69
|
+
opts = self.options.merge(opts)
|
70
|
+
if opts[:theme].is_a?(Array)
|
71
|
+
opts[:theme] = opts[:theme][rand(opts[:theme].size)]
|
72
|
+
end
|
73
|
+
opts
|
74
|
+
end
|
75
|
+
|
76
|
+
def reset_current_themes
|
77
|
+
self.current_themes = []
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tm_syntax_highlighting
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seivan Heidari
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-26 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ultraviolet
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: a gem to get syntaxhilight via ultraviolet
|
26
|
+
email: seivan@kth.se
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README
|
36
|
+
- Rakefile
|
37
|
+
- VERSION
|
38
|
+
- generators/syntax_css/syntax_css_generator.rb
|
39
|
+
- generators/syntax_css/templates/.gitignore
|
40
|
+
- init.rb
|
41
|
+
- install.rb
|
42
|
+
- lib/tm_syntax_highlighting.rb
|
43
|
+
- test/tm_syntax_highlighting_test.rb
|
44
|
+
- uninstall.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/seivan
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --charset=UTF-8
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.5
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: a gem to get syntaxhilight via ultraviolet
|
73
|
+
test_files:
|
74
|
+
- test/tm_syntax_highlighting_test.rb
|