Class: Stencil::Wrap
- Defined in:
- lib/stencil/directives/text.rb
Instance Method Summary collapse
Methods inherited from Block
#add, #ended, #initialize, #inspect, #parsed
Methods inherited from Directive
#checked_render, create, #initialize, #inspect, #inspect_args, #interpret, #parsed, #postrender, #pre_end, #prerender, register, #render_end
Constructor Details
This class inherits a constructor from Stencil::Block
Instance Method Details
#render(state) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/stencil/directives/text.rb', line 16 def render(state) env = EvaluationHost.new(state.data) width = env.run(@width_text) res = super.compact.join("") scanner = StringScanner.new(res) scanner.skip(/\s*/m) result = [] line = scanner.scan(/\S+/m) || "" until scanner.eos? white = scanner.scan(/\s*/m) white.gsub(/\n/) do |nl| result << line + "\n" line = "" end word = scanner.scan(/\S+/m) next if word.nil? if word.length > (width - line.length) result << line + "\n" line = word else line << (" " + word) end end result << line return result end |
#setup_parameters(width) ⇒ Object
12 13 14 |
# File 'lib/stencil/directives/text.rb', line 12 def setup_parameters(width) @width_text = width end |