sinatra-exstatic-assets 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rspec
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - ruby-head
6
+
7
+ # whitelist
8
+ branches:
9
+ only:
10
+ - master
11
+ - develop
data/CHANGES.md ADDED
@@ -0,0 +1,9 @@
1
+ # CH CH CH CHANGES! #
2
+
3
+ ## Saturday the 25th of May 2013, v2.0.0 ##
4
+
5
+ * First release as the renamed library.
6
+ * Bumped version number to 2 to make complete break from previous version numbers.
7
+ * Added this file!
8
+
9
+ ----
data/Gemfile ADDED
@@ -0,0 +1,29 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sinatra-static-assets.gemspec
4
+ gemspec
5
+
6
+ group :example do
7
+ gem "sinatra"
8
+ end
9
+
10
+ group :test do
11
+ gem "rspec"
12
+ gem "rack-test"
13
+ gem "simplecov"
14
+ gem 'turn', :require => false
15
+ gem "rack-test-accepts", :require => "rack/test/accepts"
16
+ end
17
+
18
+ group :development do
19
+ gem 'json', '~> 1.7.7'
20
+ gem "rake"
21
+ gem "wirble"
22
+ gem "reek"
23
+ gem 'webrick', '~> 1.3.1' # get rid of stupid warnings.
24
+ end
25
+
26
+ group :documentation do
27
+ gem "yard"
28
+ gem "maruku"
29
+ end
data/LICENCE ADDED
@@ -0,0 +1,27 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2009 Wlodek Bzyl, 2013 Iain Barnett
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+
25
+ Addendum!
26
+
27
+ The photos linked to from Flickr in the examples are not covered by this licence and are given under a Creative Commons licence. Follow the links to Flickr see the licence details.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ ## Sinatra Exstatic Assets ##
2
+
3
+ ### Master branch build status ###
4
+
5
+ [![Build Status](https://travis-ci.org/yb66/sinatra-exstatic-assets.png?branch=master)](https://travis-ci.org/yb66/sinatra-exstatic-assets)
6
+
7
+ ### Preamble ###
8
+
9
+ This is a fork/reworking of [wbzyl](https://github.com/wbzyl/sinatra-static-assets)'s library. I had many of the same requirements that the original library catered for, but some different ones too, and the beauty of open source code is you get to scratch your own itch! Many thanks to the contributors to that library for all their hard work and sharing the code.
10
+
11
+ ### What does it do? ###
12
+
13
+ It's a Sinatra extension that has some handy helpers for dealing with static assets, like stylesheets and images, in your views.
14
+
15
+ ### What's different from the other library? ###
16
+
17
+ * There's no `link_to` method (it doesn't handle assets so it was cut).
18
+ * There was a mutex in the library to handle timestamps and race conditions around that. That's gone.
19
+ * The helpers now look at the timestamp for the file they're linking to, and add that as a querystring parameter to the link displayed in the view. This will help client browsers cache the file (add something like Rack Cache to aid with this).
20
+ * There are some new options to give more control over whether the script_tag environment variable is prepended.
21
+ * More aliases, and shorter aliases.
22
+ * The tests are now a mixture of integration and unit test, but written using RSpec. There's also test coverage via SimpleCov, which is close to 100%.
23
+ * More API docs via Yardoc.
24
+
25
+ ### Version numbers ###
26
+
27
+ This library uses [semver](http://semver.org/) to version the **library**. That means the library version is ***not*** an indicator of quality but a way to manage changes.
28
+
29
+
30
+ ### Installation ###
31
+
32
+ Via Bundler, put this in your Gemfile:
33
+
34
+ gem "sinatra-exstatic-assets", :require => "sinatra/exstatic_assets", :git => "https://github.com/yb66/sinatra-exstatic-assets.git", :branch => "develop"
35
+
36
+ ### Usage ###
37
+
38
+ Here's a quick example, but there are more in the `examples` directory:
39
+
40
+ require 'sinatra'
41
+ require 'haml' # the lib doesn't rely on Haml, it's engine agnostic:)
42
+ require 'sinatra/exstatic_assets'
43
+
44
+ get "/" do
45
+ haml :index
46
+ end
47
+
48
+ @@ layout
49
+ !!!
50
+ %title Example
51
+ = favicon
52
+ = css_tag "/css/screen.css"
53
+ = js_tag "/js/helpers.js"
54
+ = js_tag "http://code.jquery.com/jquery-1.9.1.min.js"
55
+ %body
56
+ = yield
57
+
58
+ @@ index
59
+ %dt
60
+ %dd This is an interesting photo
61
+ %dl
62
+ %a{ href: "http://www.flickr.com/photos/redfernneil/1317915651/" }
63
+ = img "http://www.flickr.com/photos/redfernneil/1317915651/" width: 500, height: 250, alt: "Something about the photo"
64
+
65
+ There is also more detailed documentation on each helper in the {Sinatra::Exstatic::Helpers} API docs.
66
+
67
+ ### TODO ###
68
+
69
+ * Make it easy to pass in caching options.
70
+ * Default dirs set up for things like /css, /images etc.
71
+ * An image link tag.
72
+ * Caching of the timestamps (but I'm not sure it's needed or worth it).
73
+
74
+ ### Licence ###
75
+
76
+ See the LICENCE file.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ desc "(Re-) generate documentation and place it in the docs/ dir. Open the index.html file in there to read it."
4
+ task :docs => [:"docs:environment", :"docs:yard"]
5
+
6
+ namespace :docs do
7
+
8
+ task :environment do
9
+ ENV["RACK_ENV"] = "documentation"
10
+ end
11
+
12
+ require 'yard'
13
+
14
+ YARD::Rake::YardocTask.new :yard do |t|
15
+ t.files = ['lib/**/*.rb']
16
+ t.options = ['-odocs/'] # optional
17
+ end
18
+
19
+ end
20
+
21
+ namespace :examples do
22
+
23
+ desc "Run the examples."
24
+ task :run do
25
+ exec "bundle exec rackup examples/config.ru"
26
+ end
27
+
28
+ end
29
+
30
+
31
+ task :default => "spec"
32
+
33
+ require 'rspec/core/rake_task'
34
+
35
+ desc "Run specs"
36
+ RSpec::Core::RakeTask.new do |t|
37
+ t.pattern = "./spec/**/*_spec.rb"
38
+ end
@@ -0,0 +1,13 @@
1
+ require 'sinatra/base'
2
+ require 'sinatra/exstatic_assets'
3
+
4
+ module Example
5
+ class App < Sinatra::Base
6
+ register Sinatra::Exstatic
7
+
8
+ get "/" do
9
+ erb :index
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,93 @@
1
+ body {
2
+ width: 480px; margin: 0px 30px;
3
+ }
4
+
5
+
6
+ header[role=banner] h2 {
7
+ font-size: 18px; margin: 0px; color: #888;
8
+ font-style: italic;
9
+ }
10
+
11
+ ul { list-style-type: none }
12
+
13
+ nav ul {
14
+ list-style: none; padding: 0px; display: block;
15
+ clear: right; background-color: #888;
16
+ padding-left: 4px; height: 24px;
17
+ }
18
+
19
+ nav ul li {
20
+ display: inline; padding: 0px 20px 5px 10px;
21
+ height: 24px; border-right: 1px solid #ccc;
22
+ }
23
+
24
+ nav ul li a {
25
+ color: #993333; text-decoration: none;
26
+ font-size: 13px; font-weight: bold;
27
+ }
28
+
29
+ nav ul li a:hover {
30
+ color: #fff;
31
+ }
32
+
33
+ article > header time {
34
+ font-size: 14px; display: block; width: 26px;
35
+ padding: 2px; text-align: center; background-color: #993333;
36
+ color: #fff; font-weight: bold; -moz-border-radius: 6px;
37
+ -webkit-border-radius: 6px; border-radius: 6px; float: left;
38
+ margin-bottom: 10px;
39
+ }
40
+
41
+ article > header time span {
42
+ font-size: 10px; font-weight: normal;
43
+ text-transform: uppercase;
44
+ }
45
+
46
+ article > header h1 {
47
+ font-size: 30px; float: left;
48
+ margin:0;
49
+ margin-left: 14px;
50
+ text-shadow: 2px 2px 5px #333;
51
+ }
52
+
53
+ article > header h1 a {
54
+ color: #993333;
55
+ }
56
+
57
+ section > header h3 {
58
+ border-bottom: 1px dotted;
59
+ border-left: 1px dotted;
60
+ padding-left: 5px;
61
+ }
62
+
63
+ article > section {
64
+ margin-top: 30px;
65
+ }
66
+ article section section{
67
+ margin-bottom: 40px;
68
+ }
69
+
70
+ article > section header h1 {
71
+ font-size: 16px;
72
+ }
73
+
74
+ article p {
75
+ clear: both;
76
+ }
77
+
78
+ footer p {
79
+ text-align: center; font-size: 12px;
80
+ color: #888; margin-top: 24px;
81
+ }
82
+
83
+ code {
84
+ background: #E6E6E6;
85
+ border: 1px solid #D8D8D8;
86
+ display: block;
87
+ margin-bottom: 10px;
88
+ }
89
+
90
+ samp {
91
+ background: #F5F6CE;
92
+ display: block;
93
+ }
@@ -0,0 +1,8 @@
1
+ * {
2
+ font-family: 'Titillium Web', sans-serif;
3
+ }
4
+
5
+ header[role=banner] h1 {
6
+ font-family: 'Faster One', sans-serif;
7
+ font-size: 46px; margin: 0px;
8
+ }
Binary file
@@ -0,0 +1,90 @@
1
+ <header>
2
+ <h1>
3
+ <a href="#" title="Link to this post"
4
+ rel="bookmark">Usage</a>
5
+ </h1>
6
+ </header>
7
+ <p>Note that there is a Main App and an App2. This is to demonstrate that you can give links relative to the app, but if they are mounted with an extra prefix (using Rack#map, for example) the helper will respect that and produce the right href attribute.</p>
8
+ <section><header><h2>Installation and loading</h2></header>
9
+ <p>Start by installing:</p>
10
+ <code>gem 'sinatra-exstatic-assets'</code>
11
+ <p>Then require it in your Sinatra app.</p>
12
+ <code>require 'sinatra/exstatic_assets'</code>
13
+ </section>
14
+ <section>
15
+ <section>
16
+ <header><h2>The helpers</h2></header>
17
+ <p>Use these helpers in your views.<p>
18
+ <section id='stylesheet_tag'>
19
+ <header>
20
+ <h3>stylesheet_tag</h3>
21
+ </header>
22
+ <p>The code:
23
+ </p>
24
+ <code>stylesheet_tag "/css/screen.css"</code>
25
+ <p>Output:</p>
26
+ <samp>
27
+ <%= Rack::Utils.escape_html( stylesheet_tag "/css/screen.css") %>
28
+ </samp>
29
+ <footer><p>Also known as:
30
+ <ul>
31
+ <li><code>css_tag</code></li>
32
+ <li><code>stylesheet</code></li>
33
+ </ul>
34
+ </footer>
35
+ </section>
36
+ <section id='javascript_tag'>
37
+ <header>
38
+ <h3>javascript_tag</h3>
39
+ </header>
40
+ <p>The code:
41
+ </p>
42
+ <code>javascript_tag "http://code.jquery.com/jquery-1.9.1.min.js"</code>
43
+ <p>Output:</p>
44
+ <samp>
45
+ <%= Rack::Utils.escape_html( javascript_tag "http://code.jquery.com/jquery-1.9.1.min.js") %>
46
+ </samp>
47
+ <footer><p>Also known as:
48
+ <ul>
49
+ <li><code>javascript_include_tag</code></li>
50
+ <li><code>js_tag</code></li>
51
+ <li><code>script_tag</code></li>
52
+ </ul>
53
+ </footer>
54
+ </section>
55
+ <section id='image_tag'>
56
+ <header>
57
+ <h3>image_tag</h3>
58
+ </header>
59
+ <p>The code:
60
+ </p>
61
+ <code>image_tag "http://farm3.staticflickr.com/2474/3609420787_f7fc0e53c7.jpg", width: "500", height: "375", alt: "Magic Ball"</code>
62
+ <p>Output:</p>
63
+ <samp>
64
+ <%= Rack::Utils.escape_html( image_tag "http://farm3.staticflickr.com/2474/3609420787_f7fc0e53c7.jpg", width: "500", height: "375", alt: "Magic Ball" ) %>
65
+ </samp>
66
+ <footer><p>Also known as:
67
+ <ul>
68
+ <li><code>img_tag</code></li>
69
+ <li><code>img</code></li>
70
+ </ul>
71
+ </footer>
72
+ </section>
73
+ <section id='favicon_tag'>
74
+ <header>
75
+ <h3>favicon_tag</h3>
76
+ </header>
77
+ <p>The code:
78
+ </p>
79
+ <code>favicon_tag</code>
80
+ <p>Output:</p>
81
+ <samp>
82
+ <%= Rack::Utils.escape_html( favicon_tag ) %>
83
+ </samp>
84
+ <footer><p>Also known as:
85
+ <ul>
86
+ <li><code>favicon</code></li>
87
+ </ul>
88
+ </footer>
89
+ </section>
90
+ </section>
@@ -0,0 +1,40 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Example</title>
6
+ <%= favicon_tag %>
7
+ <%= stylesheet_tag 'http://fonts.googleapis.com/css?family=Quicksand|Faster+One|Cherry+Swash:700|Titillium+Web', rel: 'stylesheet', type: 'text/css' %>
8
+ <%= stylesheet_tag "/css/base.css" %>
9
+ <%= stylesheet_tag "/css/screen.css" %>
10
+ <%= javascript_tag "http://code.jquery.com/jquery-1.9.1.min.js" %>
11
+
12
+ </head>
13
+
14
+ <body>
15
+ <header role='banner'>
16
+ <a href="http://www.flickr.com/photos/28931095@N03/3609420787/" title="Magic Ball by Sam Bald, on Flickr"><%= image_tag "http://farm3.staticflickr.com/2474/3609420787_f7fc0e53c7.jpg", width: "500", height: "375", alt: "Magic Ball" %></a>
17
+ <hgroup>
18
+ <h1>Sinatra Exstatic Assets</h1>
19
+ <h2>Helpers for your JS, CSS and anything static</h2>
20
+ </hgroup>
21
+ </header>
22
+
23
+ <nav>
24
+ <ul>
25
+ <li><a href="/">Main app</a></li>
26
+ <li><a href="/app2">App 2</a></li>
27
+ <li><a href="https://rubygems.org/gems/sinatra-exstatic-assets">Rubygems</a></li>
28
+ <li><a href="https://github.com/yb66/sinatra-exstatic-assets">Source code</a></li>
29
+ </ul>
30
+ </nav>
31
+ <article>
32
+ <%= yield %>
33
+ </article>
34
+
35
+
36
+ <footer>
37
+ <p>&copy; <%= Time.now.year %> See the LICENCE file for more.</p>
38
+ </footer>
39
+ </body>
40
+ </html>