module Ore::Template::Helpers
Helper methods that can be used within ERb templates.
Constants
- MARKUP
Markup
helpers
Public Instance Methods
Determines whether the project will have a bin script.
@return [Boolean]
Specifies whether the project will have a bin script.
@since 0.7.0
# File lib/ore/template/helpers.rb, line 120 def bin? enabled?(:bin) end
Determines if the project is using Bundler.
@return [Boolean]
Specifies whether the project is using Bundler.
# File lib/ore/template/helpers.rb, line 170 def bundler? enabled?(:bundler) end
Determines if the project is using ‘Bundler::GemHelper`.
@return [Boolean]
Specifies whether the project is using `Bundler::GemHelper`.
@since 0.9.0
# File lib/ore/template/helpers.rb, line 182 def bundler_tasks? enabled?(:bundler_tasks) end
Determines if a template was enabled.
@return [Boolean]
Specifies whether the template was enabled.
# File lib/ore/template/helpers.rb, line 108 def enabled?(name) @enabled_templates.include?(name.to_sym) end
Determines if the project is using ‘Gem::PackageTask`.
@return [Boolean]
Specifies whether the project is using `Gem::PackageTask`.
@since 0.9.0
# File lib/ore/template/helpers.rb, line 218 def gem_package_task? enabled?(:gem_package_task) end
Determines if Git is enabled.
@return [Boolean]
Specifies whether Git was enabled.
@since 0.7.0
# File lib/ore/template/helpers.rb, line 74 def git? @scm == :git end
Determines if Hg is enabled.
@return [Boolean]
Specifies whether Hg was enabled.
@since 0.9.0
# File lib/ore/template/helpers.rb, line 86 def hg? @scm == :hg end
Renders all include files with the given name.
@param [Symbol] name
The name of the include.
@param [String] separator
The separator to join includes with.
@yield [output]
If a block is given, it will be passed the rendered include files.
@yieldparam [String] output
The combined result of the rendered include files.
@return [String, nil]
The combined result of the rendered include files. If no includes were found, `nil` will be returned.
# File lib/ore/template/helpers.rb, line 37 def includes(name,separator=$/) name = name.to_sym output_buffer = [] if @current_template_dir context = instance_eval('binding') @templates.each do |template| if template.includes.has_key?(@current_template_dir) path = template.includes[@current_template_dir][name] if path erb = ERB.new(File.read(path),nil,'-') output_buffer << erb.result(context) end end end end output = output_buffer.join(separator) output = nil if output.empty? if (block_given? && output) output = yield(output) end return output end
Creates an indentation string.
@param [Integer] n
The number of times to indent.
@param [Integer] spaces
The number of spaces to indent by.
@yield []
The given block will be used as the text.
@return [String]
The indentation string.
# File lib/ore/template/helpers.rb, line 237 def indent(n,spaces=2) @indent ||= 0 @indent += (spaces * n) margin = ' ' * @indent text = if block_given? yield.each_line.map { |line| margin + line }.join else margin end @indent -= (spaces * n) return text end
Determines if the project is using ‘Jeweler::Tasks`.
@return [Boolean]
Specifies whether the project is using `Jeweler::Tasks`.
@since 0.3.0
# File lib/ore/template/helpers.rb, line 206 def jeweler_tasks? enabled?(:jeweler_tasks) end
Determines if the project will contain RDoc
documented.
@return [Boolean]
Specifies whether the project will contain RDoc documented.
# File lib/ore/template/helpers.rb, line 130 def rdoc? enabled?(:rdoc) end
Determines if the project is using RSpec.
@return [Boolean]
Specifies whether the project is using RSpec.
# File lib/ore/template/helpers.rb, line 160 def rspec? enabled?(:rspec) end
Determines if the project is using ‘Gem::Tasks`.
@return [Boolean]
Specifies whether the project is using `Gem::Tasks`.
@since 0.9.0
# File lib/ore/template/helpers.rb, line 194 def rubygems_tasks? enabled?(:rubygems_tasks) end
Determines if SVN is enabled.
@return [Boolean]
Specifies whether SVN was enabled.
@since 0.9.0
# File lib/ore/template/helpers.rb, line 98 def svn? @scm == :svn end
Determines if the project is using test-unit.
@return [Boolean]
Specifies whether the project is using test-unit.
# File lib/ore/template/helpers.rb, line 150 def test_unit? enabled?(:test_unit) end
Escapes data for YAML encoding.
@param [String] data
The data to escape.
@return [String]
The YAML safe data.
# File lib/ore/template/helpers.rb, line 262 def yaml_escape(data) case data when String if data =~ /:\s/ data.dump elsif data.include?($/) lines = [''] data.each_line do |line| lines << " #{line.strip}" end lines.join($/) else data end else data.to_s end end
Determines if the project will contain YARD documented.
@return [Boolean]
Specifies whether the project will contain YARD documentation.
# File lib/ore/template/helpers.rb, line 140 def yard? enabled?(:yard) end