slds_on_rails 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 217ca23c820befbdb0c1f919bbd73575644d016a
4
+ data.tar.gz: a3a70548330289e1a39db9948d198234ff851191
5
+ SHA512:
6
+ metadata.gz: d44a66e0ca3ea40f1005a196ced0302087dd785b576758c5e5c929eb8615836eb8e51645f21499c0a27889a7f8c14b9b4b54ddd37aede29139bbf676d868a43d
7
+ data.tar.gz: 4eb95d49d0d632cf26231e7b0c786acfe8cfbc1d1a34ba0cd136317743808e40b6ebdc8188859fe4cf75817cf1f1dbfd25183fb653869779f82e3aeaed83dad4
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Slds
2
+ Short description and motivation.
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'slds'
9
+ ```
10
+
11
+ And then execute:
12
+ ```bash
13
+ $ bundle
14
+ ```
15
+
16
+ Or install it yourself as:
17
+ ```bash
18
+ $ gem install slds
19
+ ```
20
+
21
+ ## Setup
22
+
23
+ 1. Add to your helper:
24
+
25
+ ```ruby
26
+ module ApplicationHelper
27
+ include Slds::Helper
28
+ slds_config version: '2.3.1', debug: false
29
+ end
30
+ ```
31
+
32
+ 2. Add the link tag to your layout:
33
+
34
+ ```erb
35
+ <%= slds_link_tag 'data-turbolinks-track': 'reload' %>
36
+ ```
37
+
38
+ 3. Now you can also load images and any other asset from slds:
39
+
40
+ ```erb
41
+ # uses relative path: `/slds/images/spinners/slds_spinner.gif`
42
+ <%= image_tag slds_asset_path('images/spinners/slds_spinner.gif') %>
43
+
44
+ # uses absolute url: `https://unpkg.com/@salesforce-ux/design-system@2.3.1/assets/images/spinners/slds_spinner.gif'
45
+ <%= image_tag slds_asset_url('images/spinners/slds_spinner.gif') %>
46
+ ```
47
+
48
+ You can see all available assets on slds CDN at: https://unpkg.com/@salesforce-ux/design-system@2.3.1/assets/
49
+
50
+ ## Contributing
51
+ Contribution directions go here.
52
+
53
+ ## License
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Slds'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+
19
+ load 'rails/tasks/engine.rake'
20
+ load 'rails/tasks/statistics.rake'
21
+ require 'bundler/gem_tasks'
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+ task default: :test
@@ -0,0 +1,49 @@
1
+ module Slds
2
+ class SldsController < ApplicationController
3
+ rescue_from StandardError, with: :render_error
4
+ layout false
5
+
6
+ def show
7
+ if slds_response.code == '200' # set our response headers
8
+ expires_in Slds.max_age, 's-maxage' => Slds.s_maxage, public: true
9
+ response.headers['Surrogate-Key'] = 'DFC-SLDS-ASSETS' # allow these to be expired from fastly as a group
10
+ elsif slds_response.code == '404'
11
+ slds_response.body = 'not found'
12
+ end
13
+
14
+ render(
15
+ body: slds_response.body,
16
+ content_type: slds_response.content_type,
17
+ status: slds_response.code
18
+ )
19
+ end
20
+
21
+ private
22
+
23
+ def slds_response
24
+ @slds_response ||= Net::HTTP.get_response(item_uri)
25
+ end
26
+
27
+ # Map the given URL path to the absolute url to the Slds asset uri (server).
28
+ #
29
+ # For example: Slds.assets_path('/icons/utility-sprite/svg/symbols.svg#right') =>
30
+ # "/slds/2.2.1/assets/icons/utility-sprite/svg/symbols.svg#right"
31
+ # which maps to this path in slds itself:
32
+ # => 'https://unpkg.com/@salesforce-ux/design-system@2.2.1/assets/icons/utility-sprite/svg/symbols.svg#right"
33
+ def item_uri
34
+ path = params[:id] # eg "/icons/utility-sprite/svg/symbols.svg"
35
+ version = params[:version] # eg "2.2.1"
36
+ url = Slds.assets_url(path, version) # eg "https://unpkg.com/@salesforce-ux/design-system@#{version}/assets/icons/utility-sprite/svg/symbols.svg"
37
+ logger.debug("Slds::SldsController.item_uri: path #{path} proxied to #{url} using version #{version}") if Slds.debug
38
+
39
+ URI(url)
40
+ end
41
+
42
+ def render_error(e)
43
+ logger.error("Slds::SldsController.render_error: exception: #{e}")
44
+ e.backtrace.each { |line| logger.error line }
45
+
46
+ render(status: 500, body: 'error')
47
+ end
48
+ end
49
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Slds::Engine.routes.draw do
2
+ # This route removes the '/slds' prefix and sets version and path
3
+ # Example: '/slds/6.6.6/path_to_nowhere' => version='6.6.6' path = 'path_to_nowhere'
4
+ get ':version/*id' => 'slds#show', as: :slds, version: /[\d\.]+/, id: /\S+/
5
+ end
@@ -0,0 +1,15 @@
1
+ module Slds
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Slds
4
+
5
+ initializer 'slds', before: :load_config_initializers do
6
+ Rails.application.routes.append do
7
+ mount Slds::Engine => '/slds'
8
+ end
9
+ end
10
+
11
+ initializer 'Rails logger', after: :load_config_initializers do
12
+ Slds.logger = Rails.logger # get 'updated' rails logger
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ module Slds::Helper
2
+ module SharedMethods
3
+ def slds
4
+ @@slds ||= Slds
5
+ end
6
+ end
7
+
8
+ extend ActiveSupport::Concern
9
+ include SharedMethods
10
+
11
+ class_methods do
12
+ include SharedMethods
13
+ delegate :config, to: :slds, prefix: true
14
+ end
15
+
16
+ delegate :assets_url, :assets_path, to: :slds, prefix: true
17
+
18
+ def slds_link_tag(options = {})
19
+ stylesheet_link_tag(
20
+ slds_assets_url('styles/salesforce-lightning-design-system.min.css'),
21
+ options
22
+ )
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Slds
2
+ VERSION = '0.2.4'
3
+ end
data/lib/slds.rb ADDED
@@ -0,0 +1,64 @@
1
+ require 'slds/engine'
2
+ require 'slds/helper'
3
+
4
+ module Slds
5
+ extend self
6
+ attr_accessor :version
7
+ attr_accessor :url
8
+ attr_accessor :logger
9
+ attr_accessor :max_age
10
+ attr_accessor :s_maxage
11
+ attr_accessor :debug # for logging in the controller for each request
12
+
13
+ self.version = '2.2.1'
14
+ self.url = "https://unpkg.com/@salesforce-ux/design-system@VERSION/assets/"
15
+ self.max_age = 86400
16
+ self.s_maxage = 86400
17
+ self.debug = false
18
+
19
+ # Set the version and the url (dont mess with the url unless you know what you are doing)
20
+ # Usage: Slds.config { |slds| slds.version = '2.2.1'; slds.debug = true }
21
+ def config(options = {})
22
+ if options.present?
23
+ options.each { |key, value| send("#{key}=", value) }
24
+ else
25
+ yield self
26
+ end
27
+
28
+ validate_version(version)
29
+ end
30
+
31
+ # creates a absolute url that uses the url (unpkg.com) by prepending the url parameter.
32
+ # Note that /assets/ should not be part of your path.
33
+ # Slds.assets_url('styles/salesforce-lightning-design-system.min.css')
34
+ # => 'https://unpkg.com/@salesforce-ux/design-system@2.2.1/assets/styles/salesforce-lightning-design-system.min.css'
35
+ def assets_url(path, v = version)
36
+ validate_version(v)
37
+ url.gsub('VERSION', v) + trim_path(path)
38
+ end
39
+
40
+ # creates a relative path for the slds asset that uses the version and starts with /slds
41
+ # For example: Slds.assets_path('/icons/utility-sprite/svg/symbols.svg')
42
+ # creates this url => "/slds/2.2.1/icons/utility-sprite/svg/symbols.svg"
43
+ #
44
+ # This path can be put in your app and the Slds controller (of this gem) will handle the path
45
+ # (because it starts with /slds) and make a reverse proxy Net::http call to the url.
46
+ #
47
+ # The above url makes a http call to:
48
+ # => 'https://unpkg.com/@salesforce-ux/design-system@2.2.1/assets/icons/utility-sprite/svg/symbols.svg"
49
+ def assets_path(path, v = version)
50
+ validate_version(v)
51
+ "/slds/#{v}/#{trim_path(path)}"
52
+ end
53
+
54
+ private
55
+
56
+ def validate_version(version)
57
+ 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\.]+$/
58
+ end
59
+
60
+ # remove any leading / in the path (aka lchomp)
61
+ def trim_path(path)
62
+ path[0] == '/' ? trim_path(path[1..-1]) : path
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slds_on_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.4
5
+ platform: ruby
6
+ authors:
7
+ - Marcelo Eden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: vcr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A rails wrapper for SLDS
70
+ email:
71
+ - edendroid@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - app/controllers/slds/slds_controller.rb
80
+ - config/routes.rb
81
+ - lib/slds.rb
82
+ - lib/slds/engine.rb
83
+ - lib/slds/helper.rb
84
+ - lib/slds/version.rb
85
+ homepage: https://github.com/devforce/slds_on_rails
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.8
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: SLDS on Rails
109
+ test_files: []