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

Instance Method Details

#bin?Boolean (protected)

Determines whether the project will have a bin script.

Returns:

  • (Boolean)

    Specifies whether the project will have a bin script.

Since:

  • 0.7.0



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.

Returns:

  • (Boolean)

    Specifies whether 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.

Returns:

  • (Boolean)

    Specifies whether the project is using Bundler::GemHelper.

Since:

  • 0.9.0



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.

Returns:

  • (Boolean)

    Specifies whether the 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.

Returns:

  • (Boolean)

    Specifies whether the project is using Gem::PackageTask.

Since:

  • 0.9.0



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.

Returns:

  • (Boolean)

    Specifies whether Git was enabled.

Since:

  • 0.7.0



65
66
67
# File 'lib/ore/template/helpers.rb', line 65

def git?
  @scm == :git
end

#hg?Boolean (protected)

Determines if Hg is enabled.

Returns:

  • (Boolean)

    Specifies whether Hg was enabled.

Since:

  • 0.9.0



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.

Parameters:

  • name (Symbol)

    The name of the include.

  • separator (String) (defaults to: $/)

    The separator to join includes with.

Yields:

  • (output)

    If a block is given, it will be passed the rendered include files.

Yield Parameters:

  • output (String)

    The combined result of the rendered include files.

Returns:

  • (String, nil)

    The combined result of the rendered include files. If no includes were found, nil will be returned.



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.

Parameters:

  • n (Integer)

    The number of times to indent.

  • spaces (Integer) (defaults to: 2)

    The number of spaces to indent by.

Returns:

  • (String)

    The 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.

Returns:

  • (Boolean)

    Specifies whether the project is using Jeweler::Tasks.

Since:

  • 0.3.0



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.

Returns:

  • (Boolean)

    Specifies whether 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.

Returns:

  • (Boolean)

    Specifies whether 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.

Returns:

  • (Boolean)

    Specifies whether the project is using Gem::Tasks.

Since:

  • 0.9.0



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.

Returns:

  • (Boolean)

    Specifies whether SVN was enabled.

Since:

  • 0.9.0



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.

Returns:

  • (Boolean)

    Specifies whether 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.

Parameters:

  • data (String)

    The data to escape.

Returns:

  • (String)

    The YAML safe data.



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.

Returns:

  • (Boolean)

    Specifies whether the project will contain YARD documentation.



131
132
133
# File 'lib/ore/template/helpers.rb', line 131

def yard?
  enabled?(:yard)
end