rugments-1.0.0.beta8/ 0000755 0000764 0000764 00000000000 12544707752 013427 5 ustar pravi pravi rugments-1.0.0.beta8/LICENSE 0000644 0000764 0000764 00000005032 12544707752 014434 0 ustar pravi pravi The MIT License (MIT) Copyright (c) 2012-2014 Jeanine Adkisson Copyright (c) 2014 Stefan Tatschner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Many of the lexers in this project are adaptations of those in Pygments (pygments.org). The license for Pygments is as follows: Copyright (c) 2006-2014 by the respective authors (see AUTHORS file). All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. rugments-1.0.0.beta8/bin/ 0000755 0000764 0000764 00000000000 12544707752 014177 5 ustar pravi pravi rugments-1.0.0.beta8/bin/rugmentize 0000755 0000764 0000764 00000000072 12544707752 016315 0 ustar pravi pravi #!/usr/bin/env ruby require "thor" class Cli < Thor end rugments-1.0.0.beta8/README.md 0000644 0000764 0000764 00000016205 12544707752 014712 0 ustar pravi pravi # Rugments [](http://badge.fury.io/rb/rugments) Rouge is a pure-ruby syntax highlighter. It can highlight over 60 languages, and output HTML or ANSI 256-color text. Its HTML output is compatible with stylesheets designed for [pygments][]. If you'd like to help out with this project, assign yourself something from the [issues][] page, and send me a pull request (even if it's not done yet!). Bonus points for feature branches. In particular, I would appreciate help with the following lexers, from someone who has more experience with the language than I do: * Delphi/Pascal Also, if anyone with design skills feels like helping me make a website for rouge, I'd really appreciate the help. So far all I've got is the [demo page][pretty colors]. [issues]: https://github.com/jneen/rouge/issues "Help Out" [pygments]: http://pygments.org/ "Pygments" ## Usage First, take a look at the [pretty colors][]. [pretty colors]: http://rouge.jayferd.us/demo ``` ruby # make some nice lexed html source = File.read('/etc/bashrc') formatter = Rouge::Formatters::HTML.new(css_class: 'highlight') lexer = Rouge::Lexers::Shell.new formatter.format(lexer.lex(source)) # Get some CSS Rouge::Themes::Base16.mode(:light).render(scope: '.highlight') # Or use Theme#find with string input Rouge::Theme.find('base16.light').render(scope: '.highlight') ``` ### Full options #### Formatter options ##### css_class: 'highlight' Apply a class to the syntax-highlighted output. Set to false to not apply any css class. ##### line_numbers: false Generate line numbers. ##### start_line: 1 Index to start line numbers. ##### inline_theme: nil A `Rouge::CSSTheme` used to highlight the output with inline styles instead of classes. Allows string inputs (separate mode with a dot): ``` %w[colorful github monokai monokai.sublime thankful_eyes base16 base16.dark base16.light base16.solarized base16.monokai] ``` ##### wrap: true Wrap the highlighted content in a container. Defaults to `
`, or `` if line numbers are enabled.
#### Lexer options
##### debug: false
Print a trace of the lex on stdout
##### parent: ''
Allows you to specify which language the template is inside
#### CSS theme options
##### scope: '.highlight'
CSS selector that styles are applied to, e.g. `Rouge::Themes::Monokai.mode(:sublime).render(scope: 'code')`
Rouge aims to be simple to extend, and to be a drop-in replacement for pygments, with the same quality of output. Also, Rouge ships with a `rougify` command which allows you to easily highlight files in your terminal:
``` bash
$ rougify foo.rb
$ rougify style monokai.sublime > syntax.css
```
### Advantages to pygments.rb
* No need to [spawn Python processes](https://github.com/tmm1/pygments.rb).
### Advantages to CodeRay
* The HTML output from Rouge is fully compatible with stylesheets designed for pygments.
* The lexers are implemented with a dedicated DSL, rather than being hand-coded.
* Rouge supports every language CodeRay does except for Pascal/Delphi (pull requests happily accepted!), and more.
## You can even use it with Redcarpet
``` ruby
require 'redcarpet'
require 'rouge'
require 'rouge/plugins/redcarpet'
class HTML < Redcarpet::Render::HTML
include Rouge::Plugins::Redcarpet # yep, that's it.
end
```
If you have `:fenced_code_blocks` enabled, you can specify languages, and even options with CGI syntax, like `php?start_inline=1`, or `erb?parent=javascript`.
## Encodings
Rouge is only for UTF-8 strings. If you'd like to highlight a string with a different encoding, please convert it to UTF-8 first.
## Other integrations
* Middleman: [middleman-syntax](https://github.com/middleman/middleman-syntax) (@bhollis)
* Middleman: [middleman-rouge][] (@Linuus)
* RDoc: [rdoc-rouge][] (@zzak)
[middleman-rouge]: https://github.com/Linuus/middleman-rouge
[rdoc-rouge]: https://github.com/zzak/rdoc-rouge
## Contributing
### Installing Ruby
If you're here to implement a lexer for your awesome language, there's a good chance you don't already have a ruby development environment set up. Follow the [instructions on the wiki](https://github.com/jneen/rouge/wiki/Setting-up-Ruby) to get up and running. If you have trouble getting set up, let me know - I'm always happy to help.
### Run the tests
You can test the core of Rouge simply by running `rake` (no `bundle exec` required). It's also set up with `guard`, if you like.
To test a lexer visually, run `rackup` from the root and go to `localhost:9292/#{some_lexer}` where `some_lexer` is the tag or an alias of a lexer you'd like to test. If you add `?debug=1`, helpful debugging info will be printed on stdout.
### API Documentation
is at http://rubydoc.info/gems/rouge/frames.
### Using the lexer DSL
You can probably learn a lot just by reading through the existing lexers. Basically, a lexer consists of a collection of states, each of which has several rules. A rule consists of a regular expression and an action, which yields tokens and manipulates the state stack. Each rule in the state on top of the stack is tried *in order* until a match is found, at which point the action is run, the match consumed from the stream, and the process repeated with the new lexer on the top of the stack. Each lexer has a special state called `:root`, and the initial state stack consists of just this state.
Here's how you might use it:
``` ruby
class MyLexer < Rouge::RegexLexer
state :root do
# the "easy way"
# simple rules
rule /0x[0-9a-f]+/, Num::Hex
# simple state stack manipulation
rule /{-/, Comment, :next_state
rule /-}/, Comment, :pop!
# the "flexible way"
rule /abc/ do |m|
# m is the match, for accessing match groups manually
# you can do the following things:
pop!
push :another_state
push # assumed to be the current state
state? :some_state # check if the current state is :some_state
in_state? :some_state # check if :some_state is in the state stack
# yield a token. if no second argument is supplied, the value is
# taken to be the whole match.
# The sum of all the tokens yielded must be equivalent to the whole
# match - otherwise characters will go missing from the user's input.
token Generic::Output, m[0]
# calls SomeOtherLexer.lex(str) and yields its output. See the
# HTML lexer for a nice example of this.
# if no second argument is supplied, it is assumed to be the whole
# match string.
delegate SomeOtherLexer, str
# the context object is the lexer itself, so you can stash state here
@count ||= 0
@count += 1
# advanced: push a dynamically created anonymous state
push do
rule /.../, Generic::Output
end
end
rule /(\w+)(:)/
# "groups" yields the matched groups in order
groups Name::Label, Punctuation
end
end
start do
# this is run whenever a fresh lex is started
end
end
```
## Tips
I don't get paid to maintain rouge. If you've found this software useful, consider dropping a tip in the [bucket](http://www.gittip.com/jneen).
## License
Rouge is released under the MIT license. Please see the `LICENSE` file for more information.
rugments-1.0.0.beta8/metadata.yml 0000644 0000764 0000764 00000010167 12544707752 015737 0 ustar pravi pravi --- !ruby/object:Gem::Specification
name: rugments
version: !ruby/object:Gem::Version
version: 1.0.0.beta8
platform: ruby
authors:
- Jeanine Adkisson
- Stefan Tatschner
autorequire:
bindir: bin
cert_chain: []
date: 2015-06-28 00:00:00.000000000 Z
dependencies: []
description: Rugments aims to a be a simple,easy-to-extend drop-in replacement for
pygments.
email:
- jneen@jneen.net
- stefan@sevenbyte.org
executables:
- rugmentize
extensions: []
extra_rdoc_files: []
files:
- LICENSE
- README.md
- bin/rugmentize
- lib/rugments.rb
- lib/rugments/cli.rb
- lib/rugments/formatter.rb
- lib/rugments/formatters/html.rb
- lib/rugments/formatters/null.rb
- lib/rugments/formatters/terminal256.rb
- lib/rugments/lexer.rb
- lib/rugments/lexers/apache.rb
- lib/rugments/lexers/apache/keywords.yml
- lib/rugments/lexers/apple_script.rb
- lib/rugments/lexers/c.rb
- lib/rugments/lexers/clojure.rb
- lib/rugments/lexers/coffeescript.rb
- lib/rugments/lexers/common_lisp.rb
- lib/rugments/lexers/conf.rb
- lib/rugments/lexers/cpp.rb
- lib/rugments/lexers/csharp.rb
- lib/rugments/lexers/css.rb
- lib/rugments/lexers/dart.rb
- lib/rugments/lexers/diff.rb
- lib/rugments/lexers/elixir.rb
- lib/rugments/lexers/erb.rb
- lib/rugments/lexers/erlang.rb
- lib/rugments/lexers/factor.rb
- lib/rugments/lexers/gherkin.rb
- lib/rugments/lexers/gherkin/keywords.rb
- lib/rugments/lexers/go.rb
- lib/rugments/lexers/groovy.rb
- lib/rugments/lexers/haml.rb
- lib/rugments/lexers/handlebars.rb
- lib/rugments/lexers/haskell.rb
- lib/rugments/lexers/html.rb
- lib/rugments/lexers/http.rb
- lib/rugments/lexers/ini.rb
- lib/rugments/lexers/io.rb
- lib/rugments/lexers/java.rb
- lib/rugments/lexers/javascript.rb
- lib/rugments/lexers/literate_coffeescript.rb
- lib/rugments/lexers/literate_haskell.rb
- lib/rugments/lexers/llvm.rb
- lib/rugments/lexers/lua.rb
- lib/rugments/lexers/lua/builtins.rb
- lib/rugments/lexers/make.rb
- lib/rugments/lexers/markdown.rb
- lib/rugments/lexers/matlab.rb
- lib/rugments/lexers/matlab/builtins.rb
- lib/rugments/lexers/moonscript.rb
- lib/rugments/lexers/nginx.rb
- lib/rugments/lexers/nim.rb
- lib/rugments/lexers/objective_c.rb
- lib/rugments/lexers/ocaml.rb
- lib/rugments/lexers/perl.rb
- lib/rugments/lexers/php.rb
- lib/rugments/lexers/php/builtins.rb
- lib/rugments/lexers/plain_text.rb
- lib/rugments/lexers/prolog.rb
- lib/rugments/lexers/properties.rb
- lib/rugments/lexers/puppet.rb
- lib/rugments/lexers/python.rb
- lib/rugments/lexers/qml.rb
- lib/rugments/lexers/r.rb
- lib/rugments/lexers/racket.rb
- lib/rugments/lexers/ruby.rb
- lib/rugments/lexers/rust.rb
- lib/rugments/lexers/sass.rb
- lib/rugments/lexers/sass/common.rb
- lib/rugments/lexers/scala.rb
- lib/rugments/lexers/scheme.rb
- lib/rugments/lexers/scss.rb
- lib/rugments/lexers/sed.rb
- lib/rugments/lexers/shell.rb
- lib/rugments/lexers/slim.rb
- lib/rugments/lexers/smalltalk.rb
- lib/rugments/lexers/sml.rb
- lib/rugments/lexers/sql.rb
- lib/rugments/lexers/swift.rb
- lib/rugments/lexers/tcl.rb
- lib/rugments/lexers/tex.rb
- lib/rugments/lexers/toml.rb
- lib/rugments/lexers/vb.rb
- lib/rugments/lexers/viml.rb
- lib/rugments/lexers/viml/keywords.rb
- lib/rugments/lexers/xml.rb
- lib/rugments/lexers/yaml.rb
- lib/rugments/plugins/redcarpet.rb
- lib/rugments/regex_lexer.rb
- lib/rugments/template_lexer.rb
- lib/rugments/text_analyzer.rb
- lib/rugments/theme.rb
- lib/rugments/themes/base16.rb
- lib/rugments/themes/colorful.rb
- lib/rugments/themes/github.rb
- lib/rugments/themes/monokai.rb
- lib/rugments/themes/monokai_sublime.rb
- lib/rugments/themes/thankful_eyes.rb
- lib/rugments/token.rb
- lib/rugments/util.rb
- lib/rugments/version.rb
homepage: https://github.com/rumpelsepp/rugments
licenses:
- MIT
metadata: {}
post_install_message:
rdoc_options: []
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - ">"
- !ruby/object:Gem::Version
version: 1.3.1
requirements: []
rubyforge_project:
rubygems_version: 2.4.5
signing_key:
specification_version: 4
summary: A pure-ruby colorizer based on pygments
test_files: []
rugments-1.0.0.beta8/lib/ 0000755 0000764 0000764 00000000000 12544707752 014175 5 ustar pravi pravi rugments-1.0.0.beta8/lib/rugments.rb 0000644 0000764 0000764 00000002052 12544707752 016365 0 ustar pravi pravi require_relative 'rugments/version'
require_relative 'rugments/util'
require_relative 'rugments/text_analyzer'
require_relative 'rugments/token'
require_relative 'rugments/lexer'
require_relative 'rugments/regex_lexer'
require_relative 'rugments/template_lexer'
require_relative 'rugments/formatter'
require_relative 'rugments/theme'
module Rugments
module_function
# Highlight some text with a given lexer and formatter.
#
# @example
# Rouge.highlight('@foo = 1', 'ruby', 'html')
# Rouge.highlight('var foo = 1;', 'js', 'terminal256')
#
# # streaming - chunks become available as they are lexed
# Rouge.highlight(large_string, 'ruby', 'html') do |chunk|
# $stdout.print chunk
# end
def highlight(text, lexer, formatter, &b)
lexer = Lexer.find(lexer) unless lexer.respond_to?(:lex)
fail "unknown lexer #{lexer}" unless lexer
formatter = Formatter.find(formatter) unless formatter.respond_to?(:format)
fail "unknown formatter #{formatter}" unless formatter
formatter.format(lexer.lex(text), &b)
end
end
rugments-1.0.0.beta8/lib/rugments/ 0000755 0000764 0000764 00000000000 12544707752 016041 5 ustar pravi pravi rugments-1.0.0.beta8/lib/rugments/formatter.rb 0000644 0000764 0000764 00000001314 12544707752 020370 0 ustar pravi pravi module Rugments
# A Formatter takes a token stream and formats it for human viewing.
class Formatter
REGISTRY = {}
# Specify or get the unique tag for this formatter. This is used
# for specifying a formatter in `rougify`.
def self.tag(tag = nil)
return @tag unless tag
REGISTRY[tag] = self
@tag = tag
end
# Find a formatter class given a unique tag.
def self.find(tag)
REGISTRY[tag]
end
# Format a token stream. Delegates to {#format}.
def self.format(tokens, opts = {}, &b)
new(opts).format(tokens, &b)
end
end
end
require_relative 'formatters/html'
require_relative 'formatters/terminal256'
require_relative 'formatters/null'
rugments-1.0.0.beta8/lib/rugments/cli.rb 0000644 0000764 0000764 00000020355 12544707752 017142 0 ustar pravi pravi # not required by the main lib.
# to use this module, require 'rouge/cli'.
module Rugments
class FileReader
attr_reader :input
def initialize(input)
@input = input
end
def file
case input
when '-'
$stdin
when String
File.new(input)
when ->(i){ i.respond_to? :read }
input
end
end
def read
@read ||= begin
file.read
rescue => e
$stderr.puts "unable to open #{input}: #{e.message}"
exit 1
ensure
file.close
end
end
end
class CLI
def self.doc
return enum_for(:doc) unless block_given?
yield %|usage: rougify [command] [args...]|
yield %||
yield %|where is one of:|
yield %| highlight #{Highlight.desc}|
yield %| help #{Help.desc}|
yield %| style #{Style.desc}|
yield %| list #{List.desc}|
yield %| version #{Version.desc}|
yield %||
yield %|See `rougify help ` for more info.|
end
class Error < StandardError
attr_reader :message, :status
def initialize(message, status=1)
@message = message
@status = status
end
end
def self.parse(argv=ARGV)
argv = normalize_syntax(argv)
mode = argv.shift
klass = class_from_arg(mode)
return klass.parse(argv) if klass
case mode
when '-h', '--help', 'help', '-help'
Help.parse(argv)
else
argv.unshift(mode) if mode
Highlight.parse(argv)
end
end
def initialize(options={})
end
def self.error!(msg, status=1)
raise Error.new(msg, status)
end
def error!(*a)
self.class.error!(*a)
end
def self.class_from_arg(arg)
case arg
when 'version', '--version'
Version
when 'help'
Help
when 'highlight', 'hi'
Highlight
when 'style'
Style
when 'list'
List
end
end
class Version < CLI
def self.desc
"print the rouge version number"
end
def self.parse(*); new; end
def run
puts Rouge.version
end
end
class Help < CLI
def self.desc
"print help info"
end
def self.doc
return enum_for(:doc) unless block_given?
yield %|usage: rougify help |
yield %||
yield %|print help info for .|
end
def self.parse(argv)
opts = { :mode => CLI }
until argv.empty?
arg = argv.shift
klass = class_from_arg(arg)
if klass
opts[:mode] = klass
next
end
end
new(opts)
end
def initialize(opts={})
@mode = opts[:mode]
end
def run
@mode.doc.each(&method(:puts))
end
end
class Highlight < CLI
def self.desc
"highlight code"
end
def self.doc
return enum_for(:doc) unless block_given?
yield %[usage: rougify highlight [options...]]
yield %[ rougify highlight [options...]]
yield %[]
yield %[--input-file|-i specify a file to read, or - to use stdin]
yield %[]
yield %[--lexer|-l specify the lexer to use.]
yield %[ If not provided, rougify will try to guess]
yield %[ based on --mimetype, the filename, and the]
yield %[ file contents.]
yield %[]
yield %[--mimetype|-m specify a mimetype for lexer guessing]
yield %[]
yield %[--lexer-opts|-L specify lexer options in CGI format]
yield %[ (opt1=val1&opt2=val2)]
yield %[]
yield %[--formatter-opts|-F specify formatter options in CGI format]
yield %[ (opt1=val1&opt2=val2)]
end
def self.parse(argv)
opts = {
:formatter => 'terminal256',
:input_file => '-',
:lexer_opts => {},
:formatter_opts => {},
}
until argv.empty?
arg = argv.shift
case arg
when '--input-file', '-i'
opts[:input_file] = argv.shift
when '--mimetype', '-m'
opts[:mimetype] = argv.shift
when '--lexer', '-l'
opts[:lexer] = argv.shift
when '--formatter', '-f'
opts[:formatter] = argv.shift
when '--lexer-opts', '-L'
opts[:lexer_opts] = parse_cgi(argv.shift)
when '--formatter-opts', '-F'
opts[:formatter_opts] = parse_cgi(argv.shift)
when /^--/
error! "unknown option #{arg.inspect}"
else
opts[:input_file] = arg
end
end
new(opts)
end
def input_stream
@input_stream ||= FileReader.new(@input_file)
end
def input
@input ||= input_stream.read
end
def lexer_class
@lexer_class ||= Lexer.guess(
:filename => @input_file,
:mimetype => @mimetype,
:source => input_stream,
)
end
def lexer
@lexer ||= lexer_class.new(@lexer_opts)
end
attr_reader :input_file, :lexer_name, :mimetype, :formatter
def initialize(opts={})
@input_file = opts[:input_file]
if opts[:lexer]
@lexer_class = Lexer.find(opts[:lexer]) \
or error! "unkown lexer #{opts[:lexer].inspect}"
else
@lexer_name = opts[:lexer]
@mimetype = opts[:mimetype]
end
@lexer_opts = opts[:lexer_opts]
formatter_class = Formatter.find(opts[:formatter]) \
or error! "unknown formatter #{opts[:formatter]}"
@formatter = formatter_class.new(opts[:formatter_opts])
end
def run
formatter.format(lexer.lex(input), &method(:print))
end
private
def self.parse_cgi(str)
pairs = CGI.parse(str).map { |k, v| [k.to_sym, v.first] }
Hash[pairs]
end
end
class Style < CLI
def self.desc
"print CSS styles"
end
def self.doc
return enum_for(:doc) unless block_given?
yield %|usage: rougify style [] []|
yield %||
yield %|Print CSS styles for the given theme. Extra options are|
yield %|passed to the theme. Theme defaults to thankful_eyes.|
yield %||
yield %|options:|
yield %| --scope (default: .highlight) a css selector to scope by|
yield %||
yield %|available themes:|
yield %| #{Theme.registry.keys.sort.join(', ')}|
end
def self.parse(argv)
opts = { :theme_name => 'thankful_eyes' }
until argv.empty?
arg = argv.shift
case arg
when /--(\w+)/
opts[$1.tr('-', '_').to_sym] = argv.shift
else
opts[:theme_name] = arg
end
end
new(opts)
end
def initialize(opts)
theme_name = opts.delete(:theme_name)
theme_class = Theme.find(theme_name) \
or error! "unknown theme: #{theme_name}"
@theme = theme_class.new(opts)
end
def run
@theme.render(&method(:puts))
end
end
class List < CLI
def self.desc
"list available lexers"
end
def self.doc
return enum_for(:doc) unless block_given?
yield %|usage: rouge list|
yield %||
yield %|print a list of all available lexers with their descriptions.|
end
def self.parse(argv)
new
end
def run
puts "== Available Lexers =="
Lexer.all.sort_by(&:tag).each do |lexer|
desc = "#{lexer.desc}"
if lexer.aliases.any?
desc << " [aliases: #{lexer.aliases.join(',')}]"
end
puts "%s: %s" % [lexer.tag, desc]
puts
end
end
end
private
def self.normalize_syntax(argv)
out = []
argv.each do |arg|
case arg
when /^(--\w+)=(.*)$/
out << $1 << $2
when /^(-\w)(.+)$/
out << $1 << $2
else
out << arg
end
end
out
end
end
end
rugments-1.0.0.beta8/lib/rugments/theme.rb 0000644 0000764 0000764 00000010370 12544707752 017471 0 ustar pravi pravi module Rugments
class Theme
include Token::Tokens
class Style < Hash
def initialize(theme, hsh = {})
super()
@theme = theme
merge!(hsh)
end
[:fg, :bg].each do |mode|
define_method mode do
return self[mode] unless @theme
@theme.palette(self[mode]) if self[mode]
end
end
def render(selector, &b)
return enum_for(:render, selector).to_a.join("\n") unless b
return if empty?
yield "#{selector} {"
rendered_rules.each do |rule|
yield " #{rule};"
end
yield '}'
end
def rendered_rules(&b)
return enum_for(:rendered_rules) unless b
yield "color: #{fg}" if fg
yield "background-color: #{bg}" if bg
yield 'font-weight: bold' if self[:bold]
yield 'font-style: italic' if self[:italic]
yield 'text-decoration: underline' if self[:underline]
(self[:rules] || []).each(&b)
end
end
def styles
@styles ||= self.class.styles.dup
end
@palette = {}
def self.palette(arg = {})
@palette ||= InheritableHash.new(superclass.palette)
if arg.is_a? Hash
@palette.merge! arg
@palette
else
case arg
when /#[0-9a-f]+/i
arg
else
@palette[arg] || fail("not in palette: #{arg.inspect}")
end
end
end
@styles = {}
def self.styles
@styles ||= InheritableHash.new(superclass.styles)
end
def self.render(opts = {}, &b)
new(opts).render(&b)
end
class << self
def style(*tokens)
style = tokens.last.is_a?(Hash) ? tokens.pop : {}
style = Style.new(self, style)
tokens.each do |tok|
styles[tok] = style
end
end
def get_own_style(token)
token.token_chain.each do |anc|
return styles[anc] if styles[anc]
end
nil
end
def get_style(token)
get_own_style(token) || base_style
end
def base_style
styles[Token::Tokens::Text]
end
def name(n = nil)
return @name if n.nil?
@name = n.to_s
Theme.registry[@name] = self
end
def find(n)
registry[n.to_s]
end
def registry
@registry ||= {}
end
end
end
module HasModes
def mode(arg = :absent)
return @mode if arg == :absent
@modes ||= {}
@modes[arg] ||= get_mode(arg)
end
def get_mode(mode)
return self if self.mode == mode
new_name = "#{name}.#{mode}"
Class.new(self) { name(new_name); mode!(mode) }
end
def mode!(arg)
@mode = arg
send("make_#{arg}!")
end
end
class CSSTheme < Theme
def initialize(opts = {})
@scope = opts[:scope] || '.highlight'
end
def render(&b)
return enum_for(:render).to_a.join("\n") unless b
# shared styles for tableized line numbers
yield "#{@scope} table td { padding: 5px; }"
yield "#{@scope} table pre { margin: 0; }"
styles.each do |tok, style|
style.render(css_selector(tok), &b)
end
end
def render_base(selector, &b)
self.class.base_style.render(selector, &b)
end
def style_for(tok)
self.class.get_style(tok)
end
private
def css_selector(token)
inflate_token(token).map do |tok|
fail "unknown token: #{tok.inspect}" if tok.shortname.nil?
single_css_selector(tok)
end.join(', ')
end
def single_css_selector(token)
return @scope if token == Text
"#{@scope} .#{token.shortname}"
end
# yield all of the tokens that should be styled the same
# as the given token. Essentially this recursively all of
# the subtokens, except those which are more specifically
# styled.
def inflate_token(tok, &b)
return enum_for(:inflate_token, tok) unless block_given?
yield tok
tok.sub_tokens.each do |(_, st)|
next if styles[st]
inflate_token(st, &b)
end
end
end
end
require_relative 'themes/thankful_eyes'
require_relative 'themes/colorful'
require_relative 'themes/base16'
require_relative 'themes/github'
require_relative 'themes/monokai'
require_relative 'themes/monokai_sublime'
rugments-1.0.0.beta8/lib/rugments/token.rb 0000644 0000764 0000764 00000010277 12544707752 017515 0 ustar pravi pravi module Rugments
class Token
class << self
attr_reader :name
attr_reader :parent
attr_reader :shortname
def cache
@cache ||= {}
end
def sub_tokens
@sub_tokens ||= {}
end
def [](qualname)
return qualname unless qualname.is_a?(::String)
Token.cache[qualname]
end
def inspect
""
end
def matches?(other)
other.token_chain.include? self
end
def token_chain
@token_chain ||= ancestors.take_while { |x| x != Token }.reverse
end
def qualname
@qualname ||= token_chain.map(&:name).join('.')
end
def register!
Token.cache[qualname] = self
parent.sub_tokens[name] = self
end
def make_token(name, shortname, &b)
parent = self
Class.new(parent) do
@parent = parent
@name = name
@shortname = shortname
register!
class_eval(&b) if b
end
end
def token(name, shortname, &b)
tok = make_token(name, shortname, &b)
const_set(name, tok)
end
def each_token(&b)
Token.cache.each do |(_, t)|
b.call(t)
end
end
end
module Tokens
def self.token(name, shortname, &b)
tok = Token.make_token(name, shortname, &b)
const_set(name, tok)
end
# IMPORTANT:
# For compatibility, this list must be kept in sync with
# pygments.token.STANDARD_TYPES
# please see https://github.com/jayferd/rouge/wiki/List-of-tokens
token :Text, '' do
token :Whitespace, 'w'
end
token :Error, 'err'
token :Other, 'x'
token :Keyword, 'k' do
token :Constant, 'kc'
token :Declaration, 'kd'
token :Namespace, 'kn'
token :Pseudo, 'kp'
token :Reserved, 'kr'
token :Type, 'kt'
token :Variable, 'kv'
end
token :Name, 'n' do
token :Attribute, 'na'
token :Builtin, 'nb' do
token :Pseudo, 'bp'
end
token :Class, 'nc'
token :Constant, 'no'
token :Decorator, 'nd'
token :Entity, 'ni'
token :Exception, 'ne'
token :Function, 'nf'
token :Property, 'py'
token :Label, 'nl'
token :Namespace, 'nn'
token :Other, 'nx'
token :Tag, 'nt'
token :Variable, 'nv' do
token :Class, 'vc'
token :Global, 'vg'
token :Instance, 'vi'
end
end
token :Literal, 'l' do
token :Date, 'ld'
token :String, 's' do
token :Backtick, 'sb'
token :Char, 'sc'
token :Doc, 'sd'
token :Double, 's2'
token :Escape, 'se'
token :Heredoc, 'sh'
token :Interpol, 'si'
token :Other, 'sx'
token :Regex, 'sr'
token :Single, 's1'
token :Symbol, 'ss'
end
token :Number, 'm' do
token :Float, 'mf'
token :Hex, 'mh'
token :Integer, 'mi' do
token :Long, 'il'
end
token :Oct, 'mo'
token :Bin, 'mb'
token :Other, 'mx'
end
end
token :Operator, 'o' do
token :Word, 'ow'
end
token :Punctuation, 'p' do
token :Indicator, 'pi'
end
token :Comment, 'c' do
token :Doc, 'cd'
token :Multiline, 'cm'
token :Preproc, 'cp'
token :Single, 'c1'
token :Special, 'cs'
end
token :Generic, 'g' do
token :Deleted, 'gd'
token :Emph, 'ge'
token :Error, 'gr'
token :Heading, 'gh'
token :Inserted, 'gi'
token :Output, 'go'
token :Prompt, 'gp'
token :Strong, 'gs'
token :Subheading, 'gu'
token :Traceback, 'gt'
token :Lineno, 'gl'
end
# convenience
Num = Literal::Number
Str = Literal::String
end
end
end
rugments-1.0.0.beta8/lib/rugments/lexers/ 0000755 0000764 0000764 00000000000 12544707752 017343 5 ustar pravi pravi rugments-1.0.0.beta8/lib/rugments/lexers/puppet.rb 0000644 0000764 0000764 00000006214 12544707752 021210 0 ustar pravi pravi module Rugments
module Lexers
class Puppet < RegexLexer
title 'Puppet'
desc 'The Puppet configuration management language (puppetlabs.org)'
tag 'puppet'
aliases 'pp'
filenames '*.pp'
def self.analyze_text(text)
return 1 if text.shebang? 'puppet-apply'
return 1 if text.shebang? 'puppet'
end
def self.keywords
@keywords ||= Set.new %w(
and case class default define else elsif if in import inherits
node unless
)
end
def self.constants
@constants ||= Set.new %w(
false true undef
)
end
def self.metaparameters
@metaparameters ||= Set.new %w(
before require notify subscribe
)
end
id = /[a-z]\w*/
cap_id = /[A-Z]\w*/
qualname = /(::)?(#{id}::)*\w+/
state :whitespace do
rule /\s+/m, Text
rule /#.*?\n/, Comment
end
state :root do
mixin :whitespace
rule /[$]#{qualname}/, Name::Variable
rule /(#{id})(?=\s*[=+]>)/m do |m|
if self.class.metaparameters.include? m[0]
token Keyword::Pseudo
else
token Name::Property
end
end
rule /(#{qualname})(?=\s*[(])/m, Name::Function
rule cap_id, Name::Class
rule /[+=|~-]>|<[|~-]/, Punctuation
rule /[:}();\[\]]/, Punctuation
# HACK for case statements and selectors
rule /{/, Punctuation, :regex_allowed
rule /,/, Punctuation, :regex_allowed
rule /(in|and|or)\b/, Operator::Word
rule /[=!<>]=/, Operator
rule /[=!]~/, Operator, :regex_allowed
rule %r{[<>!+*/-]}, Operator
rule /(class|include)(\s*)(#{qualname})/ do
groups Keyword, Text, Name::Class
end
rule /node\b/, Keyword, :regex_allowed
rule /'(\\[\\']|[^'])*'/m, Str::Single
rule /"/, Str::Double, :dquotes
rule /\d+([.]\d+)?(e[+-]\d+)?/, Num
# a valid regex. TODO: regexes are only allowed
# in certain places in puppet.
rule qualname do |m|
if self.class.keywords.include? m[0]
token Keyword
elsif self.class.constants.include? m[0]
token Keyword::Constant
else
token Name
end
end
end
state :regex_allowed do
mixin :whitespace
rule %r{/}, Str::Regex, :regex
rule(//) { pop! }
end
state :regex do
rule %r{/}, Str::Regex, :pop!
rule /\\./, Str::Escape
rule /[(){}]/, Str::Interpol
rule /\[/, Str::Interpol, :regex_class
rule /./, Str::Regex
end
state :regex_class do
rule /\]/, Str::Interpol, :pop!
rule /(?