Module: Ore::Template::Helpers
- Included in:
- Generator
- Defined in:
- lib/ore/template/helpers.rb,
lib/ore/template/helpers/rdoc.rb,
lib/ore/template/helpers/textile.rb,
lib/ore/template/helpers/markdown.rb
Overview
Helper methods that can be used within ERb templates.
Defined Under Namespace
Modules: Markdown, RDoc, Textile
Constant Summary collapse
Instance Method Summary collapse
-
#bin? ⇒ Boolean
Determines whether the project will have a bin script.
-
#bundler? ⇒ Boolean
Determines if the project is using Bundler.
-
#bundler_tasks? ⇒ Boolean
Determines if the project is using
Bundler::GemHelper
. -
#enabled?(name) ⇒ Boolean
Determines if a template was enabled.
-
#gem_package_task? ⇒ Boolean
Determines if the project is using
Gem::PackageTask
. -
#git? ⇒ Boolean
Determines if Git is enabled.
-
#hg? ⇒ Boolean
Determines if Hg is enabled.
-
#includes(name, separator = $/) {|output| ... } ⇒ String?
Renders all include files with the given name.
-
#indent(n, spaces = 2) { ... } ⇒ String
Creates an indentation string.
-
#jeweler_tasks? ⇒ Boolean
Determines if the project is using
Jeweler::Tasks
. -
#rdoc? ⇒ Boolean
Determines if the project will contain RDoc documented.
-
#rspec? ⇒ Boolean
Determines if the project is using RSpec.
-
#rubygems_tasks? ⇒ Boolean
Determines if the project is using
Gem::Tasks
. -
#svn? ⇒ Boolean
Determines if SVN is enabled.
-
#test_unit? ⇒ Boolean
Determines if the project is using test-unit.
-
#yaml_escape(data) ⇒ String
Escapes data for YAML encoding.
-
#yard? ⇒ Boolean
Determines if the project will contain YARD documented.
Instance Method Details
#bin? ⇒ Boolean
Determines whether the project will have a bin script.
120 121 122 |
# File 'lib/ore/template/helpers.rb', line 120 def bin? enabled?(:bin) end |
#bundler? ⇒ Boolean
Determines if the project is using Bundler.
170 171 172 |
# File 'lib/ore/template/helpers.rb', line 170 def bundler? enabled?(:bundler) end |
#bundler_tasks? ⇒ Boolean
Determines if the project is using Bundler::GemHelper
.
182 183 184 |
# File 'lib/ore/template/helpers.rb', line 182 def bundler_tasks? enabled?(:bundler_tasks) end |
#enabled?(name) ⇒ Boolean
Determines if a template was enabled.
108 109 110 |
# File 'lib/ore/template/helpers.rb', line 108 def enabled?(name) @enabled_templates.include?(name.to_sym) end |
#gem_package_task? ⇒ Boolean
Determines if the project is using Gem::PackageTask
.
218 219 220 |
# File 'lib/ore/template/helpers.rb', line 218 def gem_package_task? enabled?(:gem_package_task) end |
#git? ⇒ Boolean
Determines if Git is enabled.
74 75 76 |
# File 'lib/ore/template/helpers.rb', line 74 def git? @scm == :git end |
#hg? ⇒ Boolean
Determines if Hg is enabled.
86 87 88 |
# File 'lib/ore/template/helpers.rb', line 86 def hg? @scm == :hg end |
#includes(name, separator = $/) {|output| ... } ⇒ String?
Renders all include files with the given name.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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 |
#indent(n, spaces = 2) { ... } ⇒ String
Creates an indentation string.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# 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 |
#jeweler_tasks? ⇒ Boolean
Determines if the project is using Jeweler::Tasks
.
206 207 208 |
# File 'lib/ore/template/helpers.rb', line 206 def jeweler_tasks? enabled?(:jeweler_tasks) end |
#rdoc? ⇒ Boolean
Determines if the project will contain RDoc documented.
130 131 132 |
# File 'lib/ore/template/helpers.rb', line 130 def rdoc? enabled?(:rdoc) end |
#rspec? ⇒ Boolean
Determines if the project is using RSpec.
160 161 162 |
# File 'lib/ore/template/helpers.rb', line 160 def rspec? enabled?(:rspec) end |
#rubygems_tasks? ⇒ Boolean
Determines if the project is using Gem::Tasks
.
194 195 196 |
# File 'lib/ore/template/helpers.rb', line 194 def rubygems_tasks? enabled?(:rubygems_tasks) end |
#svn? ⇒ Boolean
Determines if SVN is enabled.
98 99 100 |
# File 'lib/ore/template/helpers.rb', line 98 def svn? @scm == :svn end |
#test_unit? ⇒ Boolean
Determines if the project is using test-unit.
150 151 152 |
# File 'lib/ore/template/helpers.rb', line 150 def test_unit? enabled?(:test_unit) end |
#yaml_escape(data) ⇒ String
Escapes data for YAML encoding.
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# 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 |
#yard? ⇒ Boolean
Determines if the project will contain YARD documented.
140 141 142 |
# File 'lib/ore/template/helpers.rb', line 140 def yard? enabled?(:yard) end |