sinatra-asset_helpers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f304e28e2abf69bd7708d9189f11603e7b20530c
4
+ data.tar.gz: 3fffa7df5af40f0cc4dcf44bc69fdf362925cdeb
5
+ SHA512:
6
+ metadata.gz: 88b042b861d15e2ac870f043c2eac05470f5aa6e69ecbddba3335fd0db31bc2913a4449b09f9487ce520da128b328bacf753644a2105fbb90189bbae3b98e2f0
7
+ data.tar.gz: 7d8ef5a7b7c2fc98004a71718dee31a93c4883fa158787b1205b0c4ff804c1209b98fc8346509629613a19f8cadf10a658d3e0255b511bc802d52a7aa03a713a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ group :development, :test do
5
+ gem 'tilt', '~> 1.4.1'
6
+ gem 'slim', require: false
7
+ gem 'minitest', require: false
8
+ gem 'minitest-spec-context', require: false
9
+ gem 'minitest-reporters', require: false
10
+ gem 'rack-test', require: false
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eric Marden
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Sinatra::AssetHelpers
2
+
3
+ Pipeline-agnostic Asset Helpers for Sinatra
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sinatra-asset_helpers', require: 'sinatra/asset_helpers'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ Once you add it to your modular Sinatra App:
18
+
19
+ class App < Sinatra::Base
20
+ register Sinatra::AssetHelpers
21
+ end
22
+
23
+ You will be able to use the following helper methods in your templates and layout files:
24
+
25
+ stylesheet_tag('app.css, 'media')
26
+ # => <link href="/assets/app.css" media="screen" rel="stylesheet">
27
+
28
+ javascript_tag('app.js')
29
+ # => <script src="/assets/app.js"></script>
30
+
31
+ image_tag('image.png', 'image alt', 'image title')
32
+ # => <img src="/assets/image.png" alt="image alt" title="image title">
33
+
34
+ ## Options
35
+
36
+ You can set the following options in Sinatra to configure `Sinatra::AssetHelpers`:
37
+
38
+ set :assets_path, 'myassets' # defaults to: 'assets'
39
+ set :assets_host, 'https://assets.example.com' # defaults to: ENV['ASSETS_HOST']
40
+ set :manifest_path, '/path/to/manifest.json' # defaults to: "#{settings.root}/public/assets/manifest.json"
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( http://github.com/<my-github-username>/sinatra-asset_helpers/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ # environment
6
+ ENV['RACK_ENV'] ||= 'development'
7
+
8
+ # load path
9
+ lib_path = File.expand_path('../lib', __FILE__)
10
+ ($:.unshift lib_path) unless ($:.include? lib_path)
11
+
12
+ Rake::TestTask.new do |t|
13
+ t.libs << "spec"
14
+ t.pattern = "spec/**/*_spec.rb"
15
+ end
16
+
17
+ # tasks
18
+ task :default => [:test]
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module AssetHelpers
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,37 @@
1
+ require 'oj'
2
+ require "sinatra/asset_helpers/version"
3
+
4
+ module Sinatra
5
+ module AssetHelpers
6
+ module Helpers
7
+ def asset_url_for(filename)
8
+ return filename if filename =~ /^http|https|\//
9
+ halt 500, "Invalid path (#{settings.manifest_path}) to manifest.json" unless File.exists? settings.manifest_path
10
+
11
+ manifest = Oj.load(File.open(settings.manifest_path, 'r'))
12
+ file = manifest[filename]
13
+
14
+ "#{settings.assets_host}/#{settings.assets_path}/#{file}"
15
+ end
16
+
17
+ def stylesheet_tag(filename, media = 'screen')
18
+ %Q(<link href="#{asset_url_for(filename)}" media="#{media}" rel="stylesheet">)
19
+ end
20
+
21
+ def javascript_tag(filename)
22
+ %Q(<script src="#{asset_url_for(filename)}"></script>)
23
+ end
24
+
25
+ def image_tag(filename, alt = '', title = '')
26
+ %Q(<img src="#{asset_url_for(filename)}" alt="#{alt}" title="#{title}">)
27
+ end
28
+ end
29
+
30
+ def self.registered(app)
31
+ app.helpers AssetHelpers::Helpers
32
+ app.set :assets_path, 'assets'
33
+ app.set :assets_host, ENV['ASSETS_HOST']
34
+ app.set :manifest_path, File.join(app.settings.root, 'public/assets/manifest.json')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sinatra/asset_helpers/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sinatra-asset_helpers"
8
+ gem.version = Sinatra::AssetHelpers::VERSION
9
+ gem.authors = ['StyleSeek Engineering']
10
+ gem.email = ['engineering@styleseek.com']
11
+ gem.summary = %q{Pipeline-agnostic Asset Helpers for Sinatra}
12
+ gem.description = %q{Pipeline-agnostic Asset Helpers for Sinatra}
13
+ gem.homepage = ""
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files -z`.split("\x0")
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency 'sinatra'
22
+ gem.add_dependency 'oj'
23
+
24
+ gem.add_development_dependency "bundler", "~> 1.5"
25
+ gem.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ class TestApp < Sinatra::Base
6
+ register Sinatra::AssetHelpers
7
+ set :manifest_path, File.expand_path('../../support/assets/manifest.json', __FILE__)
8
+
9
+ get '/' do
10
+ slim :index
11
+ end
12
+
13
+ template :layout do
14
+ "html\n\tbody\n\t\t==yield\n"
15
+ end
16
+
17
+ template :index do
18
+ "==stylesheet_tag('app.css')\n==javascript_tag('app.js')\n==image_tag('image.png')\n"
19
+ end
20
+ end
21
+
22
+ def app
23
+ TestApp.new
24
+ end
25
+
26
+ describe Sinatra::AssetHelpers do
27
+ it "will return 200 status code" do
28
+ get "/"
29
+ last_response.status.must_equal 200
30
+ end
31
+
32
+ it "outputs a stylesheet tag" do
33
+ get '/'
34
+ last_response.body.must_match(/<link href="\/assets\/app.css" media="screen" rel="stylesheet">/)
35
+ end
36
+
37
+ it "outputs a javascript tag" do
38
+ get '/'
39
+ last_response.body.must_match(/<script src="\/assets\/app.js"><\/script>/)
40
+ end
41
+
42
+ it "outputs an image tag" do
43
+ get '/'
44
+ last_response.body.must_match(/<img src="\/assets\/image.png" alt="" title="">/)
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ ENV['RACK_ENV'] = 'test'
4
+ lib_path = File.expand_path('../lib', __FILE__)
5
+ ($:.unshift lib_path) unless ($:.include? lib_path)
6
+ require 'bundler'
7
+ Bundler.setup(:default, ENV['RACK_ENV'])
8
+
9
+ # require gem and dependencies
10
+ require 'slim'
11
+ require 'sinatra/base'
12
+ require 'sinatra/asset_helpers'
13
+
14
+ # testing stack
15
+ require 'rack/test'
16
+ require 'minitest/autorun'
17
+ require "minitest-spec-context"
18
+ require 'minitest/reporters'
19
+
20
+ # boot the infernal machine
21
+ MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
22
+ include Rack::Test::Methods
@@ -0,0 +1,3 @@
1
+ body {
2
+ background-color: #ffffff;
3
+ }
@@ -0,0 +1 @@
1
+ window.App = {};
Binary file
@@ -0,0 +1,5 @@
1
+ {
2
+ "app.css":"app.css",
3
+ "app.js":"app.js",
4
+ "image.png":"image.png"
5
+ }
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-asset_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - StyleSeek Engineering
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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: Pipeline-agnostic Asset Helpers for Sinatra
70
+ email:
71
+ - engineering@styleseek.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/sinatra/asset_helpers.rb
82
+ - lib/sinatra/asset_helpers/version.rb
83
+ - sinatra-asset_helpers.gemspec
84
+ - spec/sinatra/asset_helpers_spec.rb
85
+ - spec/spec_helper.rb
86
+ - spec/support/assets/app.css
87
+ - spec/support/assets/app.js
88
+ - spec/support/assets/image.png
89
+ - spec/support/assets/manifest.json
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.0
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Pipeline-agnostic Asset Helpers for Sinatra
114
+ test_files:
115
+ - spec/sinatra/asset_helpers_spec.rb
116
+ - spec/spec_helper.rb
117
+ - spec/support/assets/app.css
118
+ - spec/support/assets/app.js
119
+ - spec/support/assets/image.png
120
+ - spec/support/assets/manifest.json