Class: SyntaxOn
- Inherits:
-
Object
- Object
- SyntaxOn
- Defined in:
- lib/syntax-on.rb
Defined Under Namespace
Constant Summary collapse
- VIM_BIN =
'vim'
- VIM_OPTIONS =
[ "syntax on", "let html_use_css = 1", 'let html_use_encoding = "utf8"', "let use_xhtml = 1" ]
- VIM_RENDER =
[ "exe 'normal zR'", "runtime\\! syntax/2html.vim", "wq", "q" ]
- TEMP_DIRECTORY =
'/tmp/syntax-on'
- TEMP_FILENAME =
lambda { Time.now.strftime '%Y-%d-%m_%Hh-%Mm-%Ss' }
- THEME_PATH =
[ '~/.syntaxon/themes' ]
- PREVIEW_COMMAND =
lambda { |file| (Gem::Platform.local.os == 'darwin') ? "open -a Firefox '#{file}'" : "firefox '#{file}' &" }
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#syntax ⇒ Object
Returns the value of attribute syntax.
Class Method Summary collapse
- .theme(name = :remi) ⇒ Object
- .theme_directories ⇒ Object
- .theme_directory ⇒ Object
- .theme_names ⇒ Object
- .themes ⇒ Object
Instance Method Summary collapse
-
#initialize(code_or_options, options = nil) ⇒ SyntaxOn
constructor
A new instance of SyntaxOn.
- #to_html(options = { :line_numbers => @line_numbers }) ⇒ Object
Constructor Details
#initialize(code_or_options, options = nil) ⇒ SyntaxOn
Returns a new instance of SyntaxOn.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/syntax-on.rb', line 24 def initialize , = nil if .is_a?(String) ||= {} [:code] = else = end [:syntax] ||= nil if [:file] and File.file? [:file] @file = [:file] @code = File.read @file end @line_numbers = [:line_numbers].nil? ? true : [:line_numbers] @code = [:code] if @code.nil? and [:code] @syntax = [:syntax] @use_session = [:use_session] end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
22 23 24 |
# File 'lib/syntax-on.rb', line 22 def code @code end |
#syntax ⇒ Object
Returns the value of attribute syntax.
22 23 24 |
# File 'lib/syntax-on.rb', line 22 def syntax @syntax end |
Class Method Details
.theme(name = :remi) ⇒ Object
64 65 66 |
# File 'lib/syntax-on.rb', line 64 def self.theme name = :remi File.read themes.find { |theme| File.basename(theme).downcase == "#{ name }.css".downcase } end |
.theme_directories ⇒ Object
72 73 74 |
# File 'lib/syntax-on.rb', line 72 def self.theme_directories SyntaxOn::THEME_PATH << self.theme_directory end |
.theme_directory ⇒ Object
68 69 70 |
# File 'lib/syntax-on.rb', line 68 def self.theme_directory File.( File.join( File.dirname(__FILE__), "/../themes/" )) end |
.theme_names ⇒ Object
60 61 62 |
# File 'lib/syntax-on.rb', line 60 def self.theme_names themes.map { |theme| File.basename(theme).sub(/\.css$/,'') }.uniq.sort end |
.themes ⇒ Object
56 57 58 |
# File 'lib/syntax-on.rb', line 56 def self.themes theme_directories.inject([]){ |all,this| all + Dir[File.join(File.(this), '*.css')] } end |
Instance Method Details
#to_html(options = { :line_numbers => @line_numbers }) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/syntax-on.rb', line 47 def to_html = { :line_numbers => @line_numbers } setup_temp_dir create_temp_file render @html = File.read(@html_file).match(/<pre>(.*)<\/pre>/m)[1].strip finish end |