Class: Termtter::Plugins::Haml
- Inherits:
-
Object
- Object
- Termtter::Plugins::Haml
- Defined in:
- lib/plugins/haml.rb
Instance Method Summary collapse
- #editor(extname) ⇒ Object
- #haml(format) ⇒ Object
-
#initialize(config = Termtter::Config.instance, logger = Termtter::Client.logger) ⇒ Haml
constructor
A new instance of Haml.
- #plugin_config ⇒ Object
- #run(arg) ⇒ Object
Constructor Details
#initialize(config = Termtter::Config.instance, logger = Termtter::Client.logger) ⇒ Haml
Returns a new instance of Haml.
8 9 10 11 12 |
# File 'lib/plugins/haml.rb', line 8 def initialize(config = Termtter::Config.instance, logger = Termtter::Client.logger) @config, @logger = config, logger plugin_config.set_default :options, {} end |
Instance Method Details
#editor(extname) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/plugins/haml.rb', line 39 def editor(extname) unless cmd = ENV['VISUAL'] || ENV['EDITOR'] raise 'Please set VISUAL or EDITOR variable.' end # XXX: works only in Ruby 1.8.7 or later Tempfile.open(['tmp', ".#{extname}"]) do |f| system cmd, f.path return f.read end end |
#haml(format) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/plugins/haml.rb', line 32 def haml(format) return unless input = editor(:haml) opts = plugin_config..merge(format.empty? ? {} : {:format => format.to_sym}) ::Haml::Engine.new(input, opts).render.chomp end |
#plugin_config ⇒ Object
14 15 16 |
# File 'lib/plugins/haml.rb', line 14 def plugin_config @config.plugins.haml end |