Sha256: 87cdd42615ecb14e3fa373337818fb71bcb4ee2de6b6a29e895d744ae119d25f

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module RubyCritic
  module ViewHelpers
    def timeago_tag(time)
      "<time class='js-timeago' datetime='#{time}'>#{time}</time>"
    end

    def javascript_tag(file)
      "<script src='" + asset_path("javascripts/#{file}.js").to_s + "'></script>"
    end

    def stylesheet_path(file)
      asset_path("stylesheets/#{file}.css")
    end

    def asset_path(file)
      relative_path("assets/#{file}")
    end

    def image_path(file)
      asset_path("images/#{file}")
    end

    def file_path(file)
      relative_path(file)
    end

    def smell_location_path(location)
      file_path("#{location.pathname.sub_ext('.html')}#L#{location.line}")
    end

    private

    def relative_path(file)
      (root_directory + file).relative_path_from(file_directory)
    end

    def file_directory
      raise NotImplementedError,
            "The #{self.class} class must implement the #{__method__} method."
    end

    def root_directory
      raise NotImplementedError,
            "The #{self.class} class must implement the #{__method__} method."
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubycritic-3.4.0 lib/rubycritic/generators/html/view_helpers.rb
rubycritic-3.3.0 lib/rubycritic/generators/html/view_helpers.rb
rubycritic-3.2.3 lib/rubycritic/generators/html/view_helpers.rb
rubycritic-3.2.2 lib/rubycritic/generators/html/view_helpers.rb
rubycritic-3.2.1 lib/rubycritic/generators/html/view_helpers.rb