module Slds

Constants

VERSION

Attributes

debug[RW]
logger[RW]
max_age[RW]
s_maxage[RW]
url[RW]
version[RW]

Public Instance Methods

assets_path(path, v = version) click to toggle source

creates a relative path for the slds asset that uses the version and starts with /slds For example: Slds.assets_path('/icons/utility-sprite/svg/symbols.svg')

creates this url => "/slds/2.2.1/icons/utility-sprite/svg/symbols.svg"

This path can be put in your app and the Slds controller (of this gem) will handle the path (because it starts with /slds) and make a reverse proxy Net::http call to the url.

The above url makes a http call to:

=> 'https://unpkg.com/@salesforce-ux/design-system@2.2.1/assets/icons/utility-sprite/svg/symbols.svg"
# File lib/slds.rb, line 49
def assets_path(path, v = version)
  validate_version(v)
  "/slds/#{v}/#{trim_path(path)}"
end
assets_url(path, v = version) click to toggle source

creates a absolute url that uses the url (unpkg.com) by prepending the url parameter. Note that /assets/ should not be part of your path. Slds.assets_url('styles/salesforce-lightning-design-system.min.css')

=> 'https://unpkg.com/@salesforce-ux/design-system@2.2.1/assets/styles/salesforce-lightning-design-system.min.css'
# File lib/slds.rb, line 35
def assets_url(path, v = version)
  validate_version(v)
  url.gsub('VERSION', v) + trim_path(path)
end
config(options = {}) { |self| ... } click to toggle source

Set the version and the url (dont mess with the url unless you know what you are doing) Usage: Slds.config { |slds| slds.version = '2.2.1'; slds.debug = true }

# File lib/slds.rb, line 21
def config(options = {})
  if options.present?
    options.each { |key, value| send("#{key}=", value) }
  else
    yield self
  end

  validate_version(version)
end

Private Instance Methods

trim_path(path) click to toggle source

remove any leading / in the path (aka lchomp)

# File lib/slds.rb, line 61
def trim_path(path)
  path[0] == '/' ? trim_path(path[1..-1]) : path
end
validate_version(version) click to toggle source
# File lib/slds.rb, line 56
def validate_version(version)
  raise ArgumentError.new("Slds: version #{version} not of the form 2.2.2 or 2.1 or 2 or 2.3.4.5 etc.") unless version =~ /^[0-9\.]+$/
end