spinebox 0.0.1 → 0.0.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/lib/spinebox/base.rb +8 -0
- data/lib/spinebox/config.rb +29 -4
- data/lib/spinebox/erb_context.rb +51 -0
- data/lib/spinebox/routes.rb +2 -4
- data/lib/spinebox/templates/app/views/index.html.erb +14 -0
- data/lib/spinebox/templates/config/config.rb +8 -1
- data/lib/spinebox/templates/config/routes.rb +2 -2
- data/lib/spinebox/templates/public/.gitignore +0 -0
- data/lib/spinebox/version.rb +1 -1
- data/lib/spinebox.rb +1 -0
- data/spec/base_spec.rb +5 -0
- data/spec/config_spec.rb +8 -2
- data/spec/erb_context_spec.rb +38 -0
- data/spec/helpers.rb +1 -0
- data/spec/routes_spec.rb +1 -1
- metadata +6 -2
- data/lib/spinebox/templates/public/index.html +0 -14
data/lib/spinebox/base.rb
CHANGED
data/lib/spinebox/config.rb
CHANGED
@@ -1,11 +1,31 @@
|
|
1
1
|
module Spinebox
|
2
|
+
module Config
|
3
|
+
|
4
|
+
# Reset the config
|
5
|
+
def self.reset!
|
6
|
+
@@configuration = nil
|
7
|
+
end
|
8
|
+
reset!
|
9
|
+
|
10
|
+
# Offer the configuration
|
11
|
+
def self.configuration(&block)
|
12
|
+
@@configuration ||= OpenStruct.new(
|
13
|
+
:assets => Sprockets::Environment.new,
|
14
|
+
:views => Sprockets::Environment.new
|
15
|
+
)
|
16
|
+
|
17
|
+
block.call(@@configuration) if block
|
18
|
+
@@configuration
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
2
23
|
class << self
|
3
24
|
|
4
25
|
# Offers the configuration with the assets
|
5
26
|
def config
|
6
|
-
|
7
|
-
|
8
|
-
@@configuration
|
27
|
+
block = Proc.new if block_given?
|
28
|
+
Config.configuration(&block)
|
9
29
|
end
|
10
30
|
|
11
31
|
# Straight access to the assets
|
@@ -13,9 +33,14 @@ module Spinebox
|
|
13
33
|
config.assets
|
14
34
|
end
|
15
35
|
|
36
|
+
# Straight access to the views
|
37
|
+
def views
|
38
|
+
config.views
|
39
|
+
end
|
40
|
+
|
16
41
|
# Load the config
|
17
42
|
def load_config!(config = "./config/config.rb")
|
18
|
-
|
43
|
+
load config
|
19
44
|
end
|
20
45
|
|
21
46
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Spinebox
|
2
|
+
module ERBContext
|
3
|
+
|
4
|
+
# Includes javascript tags in the erb. If concatenation is disabled it returns multiple tags,
|
5
|
+
# otherwise it returns a single application tag.
|
6
|
+
def javascript_include_tag source
|
7
|
+
if Spinebox.config.concatenate
|
8
|
+
javascript_tag_for(asset_for(source, 'js'))
|
9
|
+
else
|
10
|
+
asset_for(source, 'js').to_a.map{ |asset| javascript_tag_for asset, :body => 1 }.join("\n")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Includes javascript tags in the erb. If concatenation is disabled it returns multiple tags,
|
15
|
+
# otherwise it returns a single application tag.
|
16
|
+
def stylesheet_link_tag source, options = {}
|
17
|
+
if Spinebox.config.concatenate
|
18
|
+
stylesheet_tag_for(asset_for(source, 'css'), options)
|
19
|
+
else
|
20
|
+
asset_for(source, 'css').to_a.map{ |asset| stylesheet_tag_for asset, options.merge!({ :body => 1 }) }.join("\n")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# Access an asset from the assets
|
27
|
+
def asset_for source, extension
|
28
|
+
Spinebox.assets[source.include?(".#{extension}") ? source : "#{source}.#{extension}"]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Build a javascript tag with body options
|
32
|
+
def javascript_tag_for asset, options = {}
|
33
|
+
"<script src='/assets/#{asset.logical_path}#{"?body=1" if options[:body]}' type='text/javascript'></script>"
|
34
|
+
end
|
35
|
+
|
36
|
+
# Build a stylesheet link with body options
|
37
|
+
def stylesheet_tag_for asset, new_options = {}
|
38
|
+
options = { :media => "all", :rel => "stylesheet" }.merge!(new_options)
|
39
|
+
"<link href='/assets/#{asset.logical_path}#{"?body=1" if options[:body]}' media='#{options[:media]}' rel='#{options[:rel]}' type='text/css'>"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
# Include ERB context in the ERB evaluation of sprockets
|
45
|
+
module ::Sprockets
|
46
|
+
class Context
|
47
|
+
include Spinebox::ERBContext
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/lib/spinebox/routes.rb
CHANGED
@@ -25,16 +25,14 @@ module Spinebox
|
|
25
25
|
# Returns a rack builder app with the drawn routes
|
26
26
|
def app
|
27
27
|
Routes.app || begin
|
28
|
-
|
29
|
-
Spinebox.load_config!
|
30
|
-
Spinebox.load_routes!
|
28
|
+
Spinebox.boot!
|
31
29
|
Routes.app
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
35
33
|
# Load the routes
|
36
34
|
def load_routes!(routes = "./config/routes.rb")
|
37
|
-
|
35
|
+
load routes
|
38
36
|
end
|
39
37
|
|
40
38
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Spinebox</title>
|
5
|
+
<%= stylesheet_link_tag "application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "application" %>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<h1>Spinebox</h1>
|
11
|
+
<p>Is working!</p>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -1,7 +1,14 @@
|
|
1
1
|
Spinebox.config do |config|
|
2
2
|
|
3
|
-
# Setup
|
3
|
+
# Setup assets paths
|
4
4
|
config.assets.append_path 'app/assets/javascripts'
|
5
5
|
config.assets.append_path 'app/assets/stylesheets'
|
6
|
+
config.assets.append_path 'app/assets/images'
|
7
|
+
|
8
|
+
# Setup views paths
|
9
|
+
config.views.append_path 'app/views'
|
10
|
+
|
11
|
+
# Concatenate assets or serve them seperately?
|
12
|
+
config.concatenate = false
|
6
13
|
|
7
14
|
end
|
File without changes
|
data/lib/spinebox/version.rb
CHANGED
data/lib/spinebox.rb
CHANGED
data/spec/base_spec.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -2,25 +2,31 @@ require_relative "./helpers"
|
|
2
2
|
|
3
3
|
describe Spinebox do
|
4
4
|
|
5
|
+
before(:each) do
|
6
|
+
Spinebox::Config.reset!
|
7
|
+
Dir.chdir "#{Spinebox.root}/templates"
|
8
|
+
end
|
9
|
+
|
5
10
|
it "should offer a block style config method" do
|
6
11
|
Spinebox.config do |config|
|
7
12
|
config.should be_a OpenStruct
|
8
13
|
config.assets.should be_a Sprockets::Environment
|
14
|
+
config.views.should be_a Sprockets::Environment
|
9
15
|
end
|
10
16
|
end
|
11
17
|
|
12
18
|
it "should offer a normal configuration" do
|
13
19
|
Spinebox.config.should be_a OpenStruct
|
14
20
|
Spinebox.config.assets.should be_a Sprockets::Environment
|
21
|
+
Spinebox.config.views.should be_a Sprockets::Environment
|
15
22
|
end
|
16
23
|
|
17
24
|
it "should offer straight access to the assets" do
|
18
25
|
Spinebox.assets.should be_a Sprockets::Environment
|
26
|
+
Spinebox.views.should be_a Sprockets::Environment
|
19
27
|
end
|
20
28
|
|
21
29
|
it "should load the config from the default path" do
|
22
|
-
Dir.chdir "#{Spinebox.root}/templates"
|
23
|
-
|
24
30
|
Spinebox.config.assets.paths.should have(0).paths
|
25
31
|
Spinebox.load_config!
|
26
32
|
Spinebox.config.assets.paths.should have_at_least(2).paths
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative "./helpers"
|
2
|
+
|
3
|
+
describe Spinebox::ERBContext do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Dir.chdir "#{Spinebox.root}/templates"
|
7
|
+
Spinebox.boot!
|
8
|
+
end
|
9
|
+
|
10
|
+
context "javascript" do
|
11
|
+
|
12
|
+
it "should offer asset tags concatenated" do
|
13
|
+
Spinebox.config.concatenate = true
|
14
|
+
javascript_include_tag("application").split("\n").should have(1).tag
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should offer asset tags unconcatenated" do
|
18
|
+
Spinebox.config.concatenate = false
|
19
|
+
javascript_include_tag("application").split("\n").should have_at_least(5).tags
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
context "css" do
|
25
|
+
|
26
|
+
it "should offer asset tags concatenated" do
|
27
|
+
Spinebox.config.concatenate = true
|
28
|
+
stylesheet_link_tag("application").split("\n").should have(1).tag
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should offer asset tags unconcatenated" do
|
32
|
+
Spinebox.config.concatenate = false
|
33
|
+
stylesheet_link_tag("application").split("\n").should have_at_least(1).tag
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/spec/helpers.rb
CHANGED
data/spec/routes_spec.rb
CHANGED
@@ -3,11 +3,11 @@ require_relative "./helpers"
|
|
3
3
|
describe Spinebox do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
+
Dir.chdir "#{Spinebox.root}/templates"
|
6
7
|
Spinebox::Routes.reset!
|
7
8
|
end
|
8
9
|
|
9
10
|
it "should load the routes from the default path" do
|
10
|
-
Dir.chdir "#{Spinebox.root}/templates"
|
11
11
|
Spinebox.app.should be_a Rack::URLMap
|
12
12
|
end
|
13
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spinebox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -31,6 +31,7 @@ files:
|
|
31
31
|
- lib/spinebox/command.rb
|
32
32
|
- lib/spinebox/compiler.rb
|
33
33
|
- lib/spinebox/config.rb
|
34
|
+
- lib/spinebox/erb_context.rb
|
34
35
|
- lib/spinebox/generator.rb
|
35
36
|
- lib/spinebox/routes.rb
|
36
37
|
- lib/spinebox/templates/Gemfile
|
@@ -51,14 +52,16 @@ files:
|
|
51
52
|
- lib/spinebox/templates/app/assets/javascripts/lib/spine/route.coffee
|
52
53
|
- lib/spinebox/templates/app/assets/javascripts/lib/spine/spine.coffee
|
53
54
|
- lib/spinebox/templates/app/assets/stylesheets/application.css.scss
|
55
|
+
- lib/spinebox/templates/app/views/index.html.erb
|
54
56
|
- lib/spinebox/templates/config.ru
|
55
57
|
- lib/spinebox/templates/config/config.rb
|
56
58
|
- lib/spinebox/templates/config/routes.rb
|
57
|
-
- lib/spinebox/templates/public
|
59
|
+
- lib/spinebox/templates/public/.gitignore
|
58
60
|
- lib/spinebox/version.rb
|
59
61
|
- spec/base_spec.rb
|
60
62
|
- spec/command_spec.rb
|
61
63
|
- spec/config_spec.rb
|
64
|
+
- spec/erb_context_spec.rb
|
62
65
|
- spec/generator_spec.rb
|
63
66
|
- spec/helpers.rb
|
64
67
|
- spec/routes_spec.rb
|
@@ -92,6 +95,7 @@ test_files:
|
|
92
95
|
- spec/base_spec.rb
|
93
96
|
- spec/command_spec.rb
|
94
97
|
- spec/config_spec.rb
|
98
|
+
- spec/erb_context_spec.rb
|
95
99
|
- spec/generator_spec.rb
|
96
100
|
- spec/helpers.rb
|
97
101
|
- spec/routes_spec.rb
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Spinebox</title>
|
5
|
-
<link href="/assets/application.css" media="all" rel="stylesheet" type="text/css">
|
6
|
-
<script src="/assets/application.js" type="text/javascript"></script>
|
7
|
-
</head>
|
8
|
-
<body>
|
9
|
-
|
10
|
-
<h1>Spinebox</h1>
|
11
|
-
<p>Is working!</p>
|
12
|
-
|
13
|
-
</body>
|
14
|
-
</html>
|