pinion 0.2.1 → 0.2.2
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.
- data/README.md +66 -8
- data/lib/pinion/server.rb +2 -4
- data/lib/pinion/sinatra_helpers.rb +29 -0
- data/lib/pinion/version.rb +1 -1
- metadata +24 -23
data/README.md
CHANGED
@@ -23,8 +23,56 @@ You should add pinion to your project's Gemfile.
|
|
23
23
|
|
24
24
|
# Usage
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
Pinion is intended to be easy to set up and use with any Rack app, and even simpler with Sinatra.
|
27
|
+
|
28
|
+
## With Sinatra
|
29
|
+
|
30
|
+
Pinion provides helpers to make it interact well with Sinatra. In your app:
|
31
|
+
|
32
|
+
``` ruby
|
33
|
+
require "sinatra"
|
34
|
+
require "pinion"
|
35
|
+
require "pinion/sinatra_helpers"
|
36
|
+
|
37
|
+
class YourApp < Sinatra::Base
|
38
|
+
set :pinion, Pinion::Server.new("/assets")
|
39
|
+
|
40
|
+
configure do
|
41
|
+
# Tell Pinion each type of conversion it should perform
|
42
|
+
pinion.convert :scss => :css # Sass and Coffeescript will just work if you have the gems installed
|
43
|
+
pinion.convert :coffee => :js # Conversion types correspond to file extensions. .coffee -> .js
|
44
|
+
pinion.convert :styl => :css do |file_contents|
|
45
|
+
Stylus.compile file_contents # Requires the stylus gem
|
46
|
+
end
|
47
|
+
# Tell Pinion the paths to watch for files
|
48
|
+
pinion.watch "public/javascripts"
|
49
|
+
pinion.watch "public/scss"
|
50
|
+
pinion.watch "public/stylus"
|
51
|
+
end
|
52
|
+
|
53
|
+
helpers { include Pinion::SinatraHelpers }
|
54
|
+
...
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
and your config.ru:
|
59
|
+
|
60
|
+
``` ruby
|
61
|
+
require "your_app.rb"
|
62
|
+
|
63
|
+
map YourApp.pinion.mount_point do
|
64
|
+
run YourApp.pinion
|
65
|
+
end
|
66
|
+
|
67
|
+
map "/" do
|
68
|
+
run YourApp
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
## Without Sinatra
|
73
|
+
|
74
|
+
If you're not using Sinatra, the easiest way to use Pinion is to create and mount a `Pinion::Server` instance
|
75
|
+
in your `config.ru`.
|
28
76
|
|
29
77
|
``` ruby
|
30
78
|
require "pinion"
|
@@ -33,8 +81,8 @@ require "your_app.rb"
|
|
33
81
|
MOUNT_POINT = "/assets"
|
34
82
|
pinion = Pinion::Server.new(MOUNT_POINT)
|
35
83
|
# Tell Pinion each type of conversion it should perform
|
36
|
-
pinion.convert :scss => :css
|
37
|
-
pinion.convert :coffee => :js
|
84
|
+
pinion.convert :scss => :css # Sass and Coffeescript will just work if you have the gems installed
|
85
|
+
pinion.convert :coffee => :js # Conversion types correspond to file extensions. .coffee -> .js
|
38
86
|
pinion.convert :styl => :css do |file_contents|
|
39
87
|
Stylus.compile file_contents # Requires the stylus gem
|
40
88
|
end
|
@@ -49,12 +97,15 @@ map MOUNT_POINT do
|
|
49
97
|
end
|
50
98
|
|
51
99
|
map "/" do
|
52
|
-
#
|
100
|
+
# If you want to use Pinion's helper methods inside your app, you'll have to pass in the Pinion instance to
|
101
|
+
# the app somehow.
|
53
102
|
run Your::App.new(pinion)
|
54
103
|
end
|
55
104
|
```
|
56
105
|
|
57
|
-
|
106
|
+
## App helpers
|
107
|
+
|
108
|
+
Pinion provides some helpers to help you construct links for assets.
|
58
109
|
|
59
110
|
``` erb
|
60
111
|
<head>
|
@@ -65,7 +116,14 @@ In your app, you will use pinion's helper methods to construct urls:
|
|
65
116
|
</head>
|
66
117
|
```
|
67
118
|
|
68
|
-
|
119
|
+
This assumes that you have the `Pinion::Server` instance available inside your app as `pinion`. If you're
|
120
|
+
using sinatra and `Pinion::SinatraHelpers`, then the helpers are available right in your app's scope:
|
121
|
+
|
122
|
+
``` erb
|
123
|
+
<%= css_url("style.css") %>
|
124
|
+
```
|
125
|
+
|
126
|
+
# In Production
|
69
127
|
|
70
128
|
In production, you may wish to concatenate and minify your assets before you serve them. This is done through
|
71
129
|
using asset bundles. Pinion provides a predefined bundle type, `:concatenate_and_uglify_js`, for your
|
@@ -74,7 +132,7 @@ convenience.
|
|
74
132
|
You can bundle files by putting this in your app:
|
75
133
|
|
76
134
|
``` erb
|
77
|
-
<%=
|
135
|
+
<%= pinion.js_bundle(:concatenate_and_uglify_js, "main-bundle",
|
78
136
|
"app.js",
|
79
137
|
"helpers.js",
|
80
138
|
"util.js",
|
data/lib/pinion/server.rb
CHANGED
@@ -8,12 +8,10 @@ require "pinion/static_asset"
|
|
8
8
|
|
9
9
|
module Pinion
|
10
10
|
class Server
|
11
|
-
|
12
|
-
|
13
|
-
# because we need that information before requests are handled due to #asset_url
|
11
|
+
attr_reader :mount_point
|
12
|
+
|
14
13
|
def initialize(mount_point)
|
15
14
|
@mount_point = mount_point
|
16
|
-
@file_server = Rack::File.new(Dir.pwd)
|
17
15
|
end
|
18
16
|
|
19
17
|
def convert(from_and_to, &block)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Pinion
|
2
|
+
# Set up Pinion in your sinatra app:
|
3
|
+
#
|
4
|
+
# set :pinion, Pinion::Server.new("/assets")
|
5
|
+
# configure do
|
6
|
+
# pinion.convert :scss => :css
|
7
|
+
# pinion.watch "public/css"
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# then mix in in this module in your sinatra app:
|
11
|
+
#
|
12
|
+
# helpers do
|
13
|
+
# include Pinion::SinatraHelpers
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Now you can access the Pinion::Server helper methods in your view:
|
17
|
+
#
|
18
|
+
# <head>
|
19
|
+
# <%= css_url "style.css" %>
|
20
|
+
# </head>
|
21
|
+
module SinatraHelpers
|
22
|
+
[:asset_url, :css_url, :js_url, :asset_inline, :css_inline, :js_inline, :bundle_url, :js_bundle,
|
23
|
+
:css_bundle].each do |helper|
|
24
|
+
define_method helper do |*args|
|
25
|
+
settings.pinion.send(helper, *args)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/pinion/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pinion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-03 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &20353460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *20353460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &20353040 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *20353040
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: yard
|
38
|
-
requirement: &
|
38
|
+
requirement: &20352580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *20352580
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: scope
|
49
|
-
requirement: &
|
49
|
+
requirement: &20352160 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *20352160
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rack-test
|
60
|
-
requirement: &
|
60
|
+
requirement: &20351740 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *20351740
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: coffee-script
|
71
|
-
requirement: &
|
71
|
+
requirement: &20351320 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *20351320
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: dedent
|
82
|
-
requirement: &
|
82
|
+
requirement: &20350900 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *20350900
|
91
91
|
description: ! 'Pinion is a Rack application that you can use to compile and serve
|
92
92
|
assets (such as Javascript and CSS).
|
93
93
|
|
@@ -99,17 +99,18 @@ extensions: []
|
|
99
99
|
extra_rdoc_files: []
|
100
100
|
files:
|
101
101
|
- README.md
|
102
|
-
- lib/pinion.rb
|
103
|
-
- lib/pinion/bundle.rb
|
104
|
-
- lib/pinion/error.rb
|
105
|
-
- lib/pinion/compiled_asset.rb
|
106
102
|
- lib/pinion/asset.rb
|
107
|
-
- lib/pinion/bundle_type.rb
|
108
|
-
- lib/pinion/server.rb
|
109
103
|
- lib/pinion/conversion.rb
|
104
|
+
- lib/pinion/compiled_asset.rb
|
110
105
|
- lib/pinion/environment.rb
|
111
|
-
- lib/pinion/
|
106
|
+
- lib/pinion/bundle.rb
|
107
|
+
- lib/pinion/error.rb
|
108
|
+
- lib/pinion/server.rb
|
109
|
+
- lib/pinion/bundle_type.rb
|
110
|
+
- lib/pinion/sinatra_helpers.rb
|
112
111
|
- lib/pinion/version.rb
|
112
|
+
- lib/pinion/static_asset.rb
|
113
|
+
- lib/pinion.rb
|
113
114
|
homepage: https://github.com/ooyala/pinion
|
114
115
|
licenses: []
|
115
116
|
post_install_message:
|