Class: Lookbook::CodeBeautifier
- Defined in:
- lib/lookbook/services/code/code_beautifier.rb
Instance Attribute Summary collapse
- #opts ⇒ Object readonly
- #source ⇒ Object readonly
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(source, opts = {}) ⇒ CodeBeautifier
constructor
A new instance of CodeBeautifier.
Methods inherited from Service
Constructor Details
#initialize(source, opts = {}) ⇒ CodeBeautifier
Returns a new instance of CodeBeautifier.
7 8 9 10 |
# File 'lib/lookbook/services/code/code_beautifier.rb', line 7 def initialize(source, opts = {}) @source = source.to_s @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
5 6 7 |
# File 'lib/lookbook/services/code/code_beautifier.rb', line 5 def opts @opts end |
#source ⇒ Object (readonly)
5 6 7 |
# File 'lib/lookbook/services/code/code_beautifier.rb', line 5 def source @source end |
Instance Method Details
#call ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/lookbook/services/code/code_beautifier.rb', line 12 def call language = opts.fetch(:language, "html") stripped_source = source.strip result = (language.downcase == "html") ? HtmlBeautifier.beautify(stripped_source, opts) : stripped_source result.to_s.strip.html_safe rescue source.strip.html_safe end |