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" ]
- 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' ]
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
23 24 25 26 27 28 29 30 |
# File 'lib/syntax-on.rb', line 23 def initialize code, = { :syntax => nil } @code = code if [:file] and File.file? [:file] @file = [:file] @code = File.read @file end @syntax = [:syntax] end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
21 22 23 |
# File 'lib/syntax-on.rb', line 21 def code @code end |
#syntax ⇒ Object
Returns the value of attribute syntax.
21 22 23 |
# File 'lib/syntax-on.rb', line 21 def syntax @syntax end |
Class Method Details
.theme(name = :remi) ⇒ Object
49 50 51 |
# File 'lib/syntax-on.rb', line 49 def self.theme name = :remi File.read themes.find { |theme| File.basename(theme).downcase == "#{ name }.css".downcase } end |
.theme_directories ⇒ Object
57 58 59 |
# File 'lib/syntax-on.rb', line 57 def self.theme_directories SyntaxOn::THEME_PATH << self.theme_directory end |
.theme_directory ⇒ Object
53 54 55 |
# File 'lib/syntax-on.rb', line 53 def self.theme_directory File.( File.join( File.dirname(__FILE__), "/../themes/" )) end |
.theme_names ⇒ Object
45 46 47 |
# File 'lib/syntax-on.rb', line 45 def self.theme_names themes.map { |theme| File.basename(theme).sub(/\.css$/,'') }.uniq.sort end |
.themes ⇒ Object
41 42 43 |
# File 'lib/syntax-on.rb', line 41 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
32 33 34 35 36 37 38 39 |
# File 'lib/syntax-on.rb', line 32 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 |