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, options = { :syntax => nil }) ⇒ SyntaxOn
constructor
A new instance of SyntaxOn.
- #to_html(options = { :line_numbers => true }) ⇒ Object
Constructor Details
#initialize(code, options = { :syntax => nil }) ⇒ SyntaxOn
Returns a new instance of SyntaxOn.
24 25 26 27 28 29 30 31 32 |
# File 'lib/syntax-on.rb', line 24 def initialize code, = { :syntax => nil } @code = code if [:file] and File.file? [:file] @file = [:file] @code = File.read @file end @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
51 52 53 |
# File 'lib/syntax-on.rb', line 51 def self.theme name = :remi File.read themes.find { |theme| File.basename(theme).downcase == "#{ name }.css".downcase } end |
.theme_directories ⇒ Object
59 60 61 |
# File 'lib/syntax-on.rb', line 59 def self.theme_directories SyntaxOn::THEME_PATH << self.theme_directory end |
.theme_directory ⇒ Object
55 56 57 |
# File 'lib/syntax-on.rb', line 55 def self.theme_directory File.( File.join( File.dirname(__FILE__), "/../themes/" )) end |
.theme_names ⇒ Object
47 48 49 |
# File 'lib/syntax-on.rb', line 47 def self.theme_names themes.map { |theme| File.basename(theme).sub(/\.css$/,'') }.uniq.sort end |
.themes ⇒ Object
43 44 45 |
# File 'lib/syntax-on.rb', line 43 def self.themes theme_directories.inject([]){ |all,this| all + Dir[File.join(File.(this), '*.css')] } end |
Instance Method Details
#to_html(options = { :line_numbers => true }) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/syntax-on.rb', line 34 def to_html = { :line_numbers => true } setup_temp_dir create_temp_file render @html = File.read(@html_file).match(/<pre>(.*)<\/pre>/m)[1].strip finish end |