Sha256: f058fdb95789bd906bb5e227f8e9e1a42111556d55b138d6b77099008e3a6388

Contents?: true

Size: 1.72 KB

Versions: 34

Compression:

Stored size: 1.72 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

include YARD::Templates

def only_copy?(result, example, type)
  if $COPY == :all || $COPY == example
    puts(result) unless $COPYT && $COPYT != type
  end
  $COPY ? true : false
end

def text_equals(result, expected_example)
  return if only_copy?(result, expected_example, :text)
  text_equals_string(result, example_contents(expected_example, :txt))
end

def text_equals_string(result, expected)
  result.should == expected
end

def html_equals(result, expected_example)
  return if only_copy?(result, expected_example, :html)
  html_equals_string(result, example_contents(expected_example))
end

def html_equals_string(result, expected)
  [expected, result].each do |value|
    value.gsub!(/(>)\s+|\s+(<)/, '\1\2')
    value.gsub!(/&#39;/, "'")
    value.strip!
  end
  text_equals_string(result, expected)
end

def example_contents(filename, ext = 'html')
  File.read(File.join(File.dirname(__FILE__), 'examples', "#{filename}.#{ext}"))
end

module YARD::Templates::Engine
  class << self
    public :find_template_paths
  end
end

class TestHtmlTemplateOptions < Templates::TemplateOptions
  default_attr :markup, :none
  default_attr :default_return, ""
  default_attr :format, :html
  default_attr :highlight, false
end

class TestTextTemplateOptions < Templates::TemplateOptions
  default_attr :markup, :none
  default_attr :default_return, ""
  default_attr :format, :text
  default_attr :highlight, false
end

def html_options(opts = {})
  template_options(opts, TestHtmlTemplateOptions)
end

def text_options(opts = {})
  template_options(opts, TestTextTemplateOptions)
end

def template_options(opts, klass)
  options = klass.new
  options.reset_defaults
  options.update(opts)
  options
end

Version data entries

34 entries across 28 versions & 6 rubygems

Version Path
yard-0.8.7 spec/templates/spec_helper.rb
challah-1.0.0 vendor/bundle/gems/yard-0.8.6.1/spec/templates/spec_helper.rb
yard-0.8.6.2 spec/templates/spec_helper.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.6.1/spec/templates/spec_helper.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.6/spec/templates/spec_helper.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.5.2/spec/templates/spec_helper.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/templates/spec_helper.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/templates/spec_helper.rb
yard-0.8.6.1 spec/templates/spec_helper.rb
challah-1.0.0.beta2 vendor/bundle/gems/yard-0.8.5.2/spec/templates/spec_helper.rb
challah-1.0.0.beta2 vendor/bundle/gems/yard-0.8.6/spec/templates/spec_helper.rb
yard-0.8.6 spec/templates/spec_helper.rb
challah-1.0.0.beta vendor/bundle/gems/yard-0.8.5.2/spec/templates/spec_helper.rb
yard-0.8.5.2 spec/templates/spec_helper.rb