dasil003-tm_syntax_highlighting 1.9.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 ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008, 2010 [Arya Asemanfar, Gabe da Silveira]
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.md ADDED
@@ -0,0 +1,71 @@
1
+ # TmSyntaxHighlighting
2
+
3
+
4
+
5
+ ## Gems, Generators and Versions
6
+
7
+ TextMate theme based highlighting for Ruby 1.9.2 and Rails 3.
8
+
9
+ This plugin was originally written by Arya Asemanfar. Rails 3 generator and 1.9.2 compatibility by Gabe da Silveira.
10
+
11
+ I namespaced it as dasil003-tm_syntax_highlighting to avoid interference with the original. **This version is incompatible
12
+ with Ruby 1.8.x**
13
+
14
+
15
+
16
+ ## Installation
17
+
18
+ You may remember the setup for this plugin being complicated. Well that was in Ruby 1.8 land. Ruby 1.9 has oniguruma
19
+ built-in and thus everything becomes much less painful:
20
+
21
+ $ gem install dasil003-tm_syntax_highlighting
22
+
23
+ which will also install `spox-ultraviolet`, the covertly 1.9 compatible version of ultraviolet.
24
+
25
+
26
+
27
+ ## CSS Generator
28
+
29
+ It just copies all the syntax files from ultraviolet into your stylesheets directory. I haven't had time to figure out
30
+ the Thor setup in Rails 3, so sue me.
31
+
32
+ # generate all the ultraviolet css theme files in public/stylesheets/syntax/*
33
+ $ rails generate syntax_css
34
+
35
+
36
+
37
+ ## Examples
38
+
39
+ The plugin adds 2 view helper methods: `code` and `syntax_css`
40
+
41
+
42
+ ### code (helper method) usage
43
+
44
+ code(some_ruby_code, :theme => "twilight", :lang => "ruby", :line_numbers => true)
45
+
46
+ `lang` and `line_numbers` are optional. `lang` will default to plain_text and `line_numbers` will default to true.
47
+
48
+ It is *HIGHLY* recommended that you fragment cache or some other type of caching for code fragments because `ultraviolet` is fairly slow.
49
+
50
+ Theme can be an array, and one will be chosen at random.
51
+
52
+ You can set defaults in an initializer:
53
+
54
+ # config/initializers/tm_syntax_config.rb
55
+ TmSyntaxHighlighting.defaults = {:theme => "sunburst", :line_numbers => true, :lang => "ruby"}
56
+
57
+ Again, theme can be an array and will be chosen at random.
58
+
59
+
60
+ ### syntax_css (helper_method) usage
61
+
62
+ The syntax_css method will include the stylesheet tags for the themes. You can call it with a theme name
63
+
64
+ syntax_css("twilight")
65
+
66
+ or if you call it with no options, it will include all the css files for the themes used in this request
67
+
68
+ code(some_ruby_code, :theme => "twilight")
69
+ code(some_more_ruby_code, :theme => "sunburst")
70
+ ...
71
+ syntax_css # yields stylesheet tags for both twilight and sunburst
data/Rakefile ADDED
@@ -0,0 +1,39 @@
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 tm_syntax_highlighting plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the tm_syntax_highlighting plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'TmSyntaxHighlighting'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
23
+
24
+ begin
25
+ require 'jeweler'
26
+ Jeweler::Tasks.new do |gemspec|
27
+ gemspec.name = "dasil003-tm_syntax_highlighting"
28
+ gemspec.summary = "Ruby 1.9.2 / Rails 3 plugin to highlight code"
29
+ gemspec.description = "Uses the spox-ultraviolet gem to highlight any language that TextMate can highlight, and has a (Thor) generator to generate the relevant CSS files."
30
+ gemspec.email = "gabe@websaviour.com"
31
+ gemspec.homepage = "http://github.com/dasil003/tm_syntax_highlighting"
32
+ gemspec.authors = ["Arya Asemanfar", "Gabe da Silveira"]
33
+
34
+ gemspec.add_dependency('spox-ultraviolet')
35
+ end
36
+ Jeweler::GemcutterTasks.new
37
+ rescue LoadError
38
+ puts "Jeweler not available. Install it with: gem install jeweler"
39
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.9.0
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dasil003-tm_syntax_highlighting}
8
+ s.version = "1.9.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Arya Asemanfar", "Gabe da Silveira"]
12
+ s.date = %q{2010-11-17}
13
+ s.description = %q{Uses the spox-ultraviolet gem to highlight any language that TextMate can highlight, and has a (Thor) generator to generate the relevant CSS files.}
14
+ s.email = %q{gabe@websaviour.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "MIT-LICENSE",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "dasil003-tm_syntax_highlighting.gemspec",
24
+ "lib/generators/USAGE",
25
+ "lib/generators/syntax_css_generator.rb",
26
+ "lib/tm_syntax_highlighting.rb",
27
+ "lib/tm_syntax_highlighting/base.rb",
28
+ "test/tm_syntax_highlighting_test.rb",
29
+ "tm_syntax_highlighting.gemspec"
30
+ ]
31
+ s.homepage = %q{http://github.com/dasil003/tm_syntax_highlighting}
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.7}
34
+ s.summary = %q{Ruby 1.9.2 / Rails 3 plugin to highlight code}
35
+ s.test_files = [
36
+ "test/tm_syntax_highlighting_test.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<spox-ultraviolet>, [">= 0"])
45
+ else
46
+ s.add_dependency(%q<spox-ultraviolet>, [">= 0"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<spox-ultraviolet>, [">= 0"])
50
+ end
51
+ end
52
+
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates the TextMate theme CSS files from Ultraviolet
3
+
4
+ Example:
5
+ rails generate syntax_css
6
+
7
+ This will create the files at:
8
+ public/stylesheets/syntax/*
@@ -0,0 +1,10 @@
1
+ require 'rails/generators'
2
+
3
+ class SyntaxCssGenerator < Rails::Generators::Base
4
+ def install_syntax_css
5
+ Uv.themes.each do |theme|
6
+ fullpath = File.join(Uv.path, "render", "xhtml", "files", "css", "#{theme}.css")
7
+ copy_file(fullpath, "public/stylesheets/syntax/#{theme}.css")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ require 'uv'
2
+
3
+ require 'action_controller'
4
+
5
+ require 'tm_syntax_highlighting/base'
6
+
7
+ ActionView::Base.send(:include, TmSyntaxHighlighting::Helper)
8
+ ActionController::Base.send(:extend, TmSyntaxHighlighting::Controller)
@@ -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
@@ -0,0 +1,21 @@
1
+ require 'tm_syntax_highlighting'
2
+ require 'test/unit'
3
+
4
+ class TmSyntaxHighlightingTest < Test::Unit::TestCase
5
+ def test_action_controller_methods_inclusion
6
+ assert ActionController::Base.instance_methods.include?(:reset_syntax_css_includes)
7
+ end
8
+
9
+ def test_action_view_methods_inclusion
10
+ assert ActionView::Base.instance_methods.include?(:code), ':code not included'
11
+ assert ActionView::Base.instance_methods.include?(:syntax_css), ':syntax_css not included'
12
+ end
13
+
14
+ def test_code_helper
15
+ @view = ActionView::Base.new
16
+ html = @view.code("def ruby_method(param)\n return :foo\nend", :lang => 'ruby')
17
+ assert_match /span class="line-numbers"/, html, "no line number span found"
18
+ assert_match /span class="Keyword"/, html, "no keyword span found"
19
+ assert_match /span class="FunctionName"/, html, "no function name span found"
20
+ end
21
+ end
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{tm_syntax_highlighting}
8
+ s.version = "1.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Arya Asemanfar", "Gabe da Silveira"]
12
+ s.date = %q{2010-01-21}
13
+ s.description = %q{Uses the Ultraviolet gem to highlight any language that TextMate can highlight, and has a (Thor) generator to generate the relevant CSS files.}
14
+ s.email = %q{gabe@websaviour.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "install.rb",
25
+ "lib/generators/USAGE",
26
+ "lib/generators/syntax_css_generator.rb",
27
+ "lib/tm_syntax_highlighting.rb",
28
+ "lib/tm_syntax_highlighting/base.rb",
29
+ "test/tm_syntax_highlighting_test.rb",
30
+ "tm_syntax_highlighting.gemspec",
31
+ "uninstall.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/dasil003/tm_syntax_highlighting}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.5}
37
+ s.summary = %q{Gem plugin for Rails 3 to highlight code}
38
+ s.test_files = [
39
+ "test/tm_syntax_highlighting_test.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<ultraviolet>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<ultraviolet>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<ultraviolet>, [">= 0"])
53
+ end
54
+ end
55
+
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dasil003-tm_syntax_highlighting
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 9
8
+ - 0
9
+ version: 1.9.0
10
+ platform: ruby
11
+ authors:
12
+ - Arya Asemanfar
13
+ - Gabe da Silveira
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-17 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: spox-ultraviolet
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Uses the spox-ultraviolet gem to highlight any language that TextMate can highlight, and has a (Thor) generator to generate the relevant CSS files.
35
+ email: gabe@websaviour.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - README.md
42
+ files:
43
+ - MIT-LICENSE
44
+ - README.md
45
+ - Rakefile
46
+ - VERSION
47
+ - dasil003-tm_syntax_highlighting.gemspec
48
+ - lib/generators/USAGE
49
+ - lib/generators/syntax_css_generator.rb
50
+ - lib/tm_syntax_highlighting.rb
51
+ - lib/tm_syntax_highlighting/base.rb
52
+ - test/tm_syntax_highlighting_test.rb
53
+ - tm_syntax_highlighting.gemspec
54
+ has_rdoc: true
55
+ homepage: http://github.com/dasil003/tm_syntax_highlighting
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.7
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Ruby 1.9.2 / Rails 3 plugin to highlight code
86
+ test_files:
87
+ - test/tm_syntax_highlighting_test.rb