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

MARKUP =

Markup helpers

{
  markdown: Markdown,
  textile:  Textile,
  rdoc:     RDoc
}

Instance Method Summary collapse

Instance Method Details

#bin?Boolean

Determines whether the project will have a bin script.

Returns:

  • (Boolean)

    Specifies whether the project will have a bin script.

Since:

  • 0.7.0


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.

Returns:

  • (Boolean)

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

Returns:

  • (Boolean)

    Specifies whether the project is using Bundler::GemHelper.

Since:

  • 0.9.0


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.

Returns:

  • (Boolean)

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

Returns:

  • (Boolean)

    Specifies whether the project is using Gem::PackageTask.

Since:

  • 0.9.0


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.

Returns:

  • (Boolean)

    Specifies whether Git was enabled.

Since:

  • 0.7.0


74
75
76
# File 'lib/ore/template/helpers.rb', line 74

def git?
  @scm == :git
end

#hg?Boolean

Determines if Hg is enabled.

Returns:

  • (Boolean)

    Specifies whether Hg was enabled.

Since:

  • 0.9.0


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.

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.


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.

Parameters:

  • n (Integer)

    The number of times to indent.

  • spaces (Integer) (defaults to: 2)

    The number of spaces to indent by.

Yields:

  • [] The given block will be used as the text.

Returns:

  • (String)

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

Returns:

  • (Boolean)

    Specifies whether the project is using Jeweler::Tasks.

Since:

  • 0.3.0


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.

Returns:

  • (Boolean)

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

Returns:

  • (Boolean)

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

Returns:

  • (Boolean)

    Specifies whether the project is using Gem::Tasks.

Since:

  • 0.9.0


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.

Returns:

  • (Boolean)

    Specifies whether SVN was enabled.

Since:

  • 0.9.0


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.

Returns:

  • (Boolean)

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

Parameters:

  • data (String)

    The data to escape.

Returns:

  • (String)

    The YAML safe data.


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.

Returns:

  • (Boolean)

    Specifies whether the project will contain YARD documentation.


140
141
142
# File 'lib/ore/template/helpers.rb', line 140

def yard?
  enabled?(:yard)
end