Class: Erbf::Formatter::EmbeddedLanguageFormatter
- Inherits:
-
Object
- Object
- Erbf::Formatter::EmbeddedLanguageFormatter
- Defined in:
- lib/erbf/formatter/embedded_language_formatter.rb
Instance Method Summary collapse
- #format(type, content, line_length) ⇒ Object
-
#initialize(config) ⇒ EmbeddedLanguageFormatter
constructor
A new instance of EmbeddedLanguageFormatter.
- #supported?(type) ⇒ Boolean
Constructor Details
#initialize(config) ⇒ EmbeddedLanguageFormatter
Returns a new instance of EmbeddedLanguageFormatter.
6 7 8 |
# File 'lib/erbf/formatter/embedded_language_formatter.rb', line 6 def initialize(config) @config = config end |
Instance Method Details
#format(type, content, line_length) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/erbf/formatter/embedded_language_formatter.rb', line 14 def format(type, content, line_length) formatter = find(type) return content.chomp if formatter.nil? command = sprintf(formatter[:command], line_length: line_length) logger.debug(self.class.to_s) { "Formatting #{type}: #{command}" } stdout, stderr, status = Open3.capture3({}, command, { stdin_data: content }) if status.exitstatus != 0 logger.error(self.class.to_s) { "[#{command}] exit status: #{status.exitstatus}" } logger.warn(self.class.to_s) { "[#{command}] stderr output:\n#{stderr}" } unless stderr.empty? logger.debug(self.class.to_s) { "[#{command}] input was:\n#{content}" } end status.exitstatus.zero? ? stdout.chomp : content.chomp end |
#supported?(type) ⇒ Boolean
10 11 12 |
# File 'lib/erbf/formatter/embedded_language_formatter.rb', line 10 def supported?(type) !find(type).nil? end |