Module: Ore::Template::Helpers
- Included in:
- Generator
- Defined in:
- lib/ore/template/helpers.rb
Overview
Helper methods that can be used within ERb templates.
Instance Method Summary collapse
-
#bin? ⇒ Boolean
protected
Determines whether the project will have a bin script.
-
#bundler? ⇒ Boolean
protected
Determines if the project is using Bundler.
-
#bundler_tasks? ⇒ Boolean
protected
Determines if the project is using
Bundler::GemHelper
. -
#enabled?(name) ⇒ Boolean
protected
Determines if a template was enabled.
-
#gem_package_task? ⇒ Boolean
protected
Determines if the project is using
Gem::PackageTask
. -
#git? ⇒ Boolean
protected
Determines if Git is enabled.
-
#hg? ⇒ Boolean
protected
Determines if Hg is enabled.
-
#includes(name, separator = $/) {|output| ... } ⇒ String?
protected
Renders all include files with the given name.
-
#indent(n, spaces = 2) ⇒ String
protected
Creates an indentation string.
-
#jeweler_tasks? ⇒ Boolean
protected
Determines if the project is using
Jeweler::Tasks
. -
#rdoc? ⇒ Boolean
protected
Determines if the project will contain RDoc documented.
-
#rspec? ⇒ Boolean
protected
Determines if the project is using RSpec.
-
#rubygems_tasks? ⇒ Boolean
protected
Determines if the project is using
Gem::Tasks
. -
#svn? ⇒ Boolean
protected
Determines if SVN is enabled.
-
#test_unit? ⇒ Boolean
protected
Determines if the project is using test-unit.
-
#yaml_escape(data) ⇒ String
protected
Escapes data for YAML encoding.
-
#yard? ⇒ Boolean
protected
Determines if the project will contain YARD documented.
Instance Method Details
#bin? ⇒ Boolean (protected)
Determines whether the project will have a bin script.
111 112 113 |
# File 'lib/ore/template/helpers.rb', line 111 def bin? enabled?(:bin) end |
#bundler? ⇒ Boolean (protected)
Determines if the project is using Bundler.
161 162 163 |
# File 'lib/ore/template/helpers.rb', line 161 def bundler? enabled?(:bundler) end |
#bundler_tasks? ⇒ Boolean (protected)
Determines if the project is using Bundler::GemHelper
.
173 174 175 |
# File 'lib/ore/template/helpers.rb', line 173 def bundler_tasks? enabled?(:bundler_tasks) end |
#enabled?(name) ⇒ Boolean (protected)
Determines if a template was enabled.
99 100 101 |
# File 'lib/ore/template/helpers.rb', line 99 def enabled?(name) @enabled_templates.include?(name.to_sym) end |
#gem_package_task? ⇒ Boolean (protected)
Determines if the project is using Gem::PackageTask
.
209 210 211 |
# File 'lib/ore/template/helpers.rb', line 209 def gem_package_task? enabled?(:gem_package_task) end |
#git? ⇒ Boolean (protected)
Determines if Git is enabled.
65 66 67 |
# File 'lib/ore/template/helpers.rb', line 65 def git? @scm == :git end |
#hg? ⇒ Boolean (protected)
Determines if Hg is enabled.
77 78 79 |
# File 'lib/ore/template/helpers.rb', line 77 def hg? @scm == :hg end |
#includes(name, separator = $/) {|output| ... } ⇒ String? (protected)
Renders all include files with the given name.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ore/template/helpers.rb', line 28 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 |
#indent(n, spaces = 2) ⇒ String (protected)
Creates an indentation string.
225 226 227 |
# File 'lib/ore/template/helpers.rb', line 225 def indent(n,spaces=2) (' ' * spaces) * n end |
#jeweler_tasks? ⇒ Boolean (protected)
Determines if the project is using Jeweler::Tasks
.
197 198 199 |
# File 'lib/ore/template/helpers.rb', line 197 def jeweler_tasks? enabled?(:jeweler_tasks) end |
#rdoc? ⇒ Boolean (protected)
Determines if the project will contain RDoc documented.
121 122 123 |
# File 'lib/ore/template/helpers.rb', line 121 def rdoc? enabled?(:rdoc) end |
#rspec? ⇒ Boolean (protected)
Determines if the project is using RSpec.
151 152 153 |
# File 'lib/ore/template/helpers.rb', line 151 def rspec? enabled?(:rspec) end |
#rubygems_tasks? ⇒ Boolean (protected)
Determines if the project is using Gem::Tasks
.
185 186 187 |
# File 'lib/ore/template/helpers.rb', line 185 def rubygems_tasks? enabled?(:rubygems_tasks) end |
#svn? ⇒ Boolean (protected)
Determines if SVN is enabled.
89 90 91 |
# File 'lib/ore/template/helpers.rb', line 89 def svn? @scm == :svn end |
#test_unit? ⇒ Boolean (protected)
Determines if the project is using test-unit.
141 142 143 |
# File 'lib/ore/template/helpers.rb', line 141 def test_unit? enabled?(:test_unit) end |
#yaml_escape(data) ⇒ String (protected)
Escapes data for YAML encoding.
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/ore/template/helpers.rb', line 238 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 |
#yard? ⇒ Boolean (protected)
Determines if the project will contain YARD documented.
131 132 133 |
# File 'lib/ore/template/helpers.rb', line 131 def yard? enabled?(:yard) end |