middleman-target 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +94 -0
- data/examples/config.rb +14 -0
- data/examples/source/index.html.erb +32 -0
- data/lib/middleman-target.rb +53 -0
- data/spec/lib/middleman-target_spec.rb +155 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +0 -0
- metadata +95 -0
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Middleman-Target
|
2
|
+
|
3
|
+
Middleman-Target is an extension to [MIDDLEMAN] 2.0.x to allow you to specify a build target and generate the content accordingly.
|
4
|
+
|
5
|
+
You can use Middleman-Target in your Middleman project to build multiple versions of your source from one source tree.
|
6
|
+
|
7
|
+
# Examples
|
8
|
+
|
9
|
+
## Simple
|
10
|
+
|
11
|
+
ERB code:
|
12
|
+
|
13
|
+
<p>
|
14
|
+
<%# NOTE: target?() is a shorthand alias for build_target_is?() %>
|
15
|
+
<% if build_target_is?(:foo) %>
|
16
|
+
Foo specific stuff.
|
17
|
+
<% elsif target?(:bar) %>
|
18
|
+
Bar specific stuff.
|
19
|
+
<% else %>
|
20
|
+
The build target <%= build_target %> has no special needs.
|
21
|
+
<% end %>
|
22
|
+
</p>
|
23
|
+
|
24
|
+
Output when run with a build target of 'foo':
|
25
|
+
|
26
|
+
Foo specific stuff.
|
27
|
+
|
28
|
+
..'bar':
|
29
|
+
|
30
|
+
Bar specific stuff.
|
31
|
+
|
32
|
+
..anything else ('baz' in this case):
|
33
|
+
|
34
|
+
The build target baz has no special needs.
|
35
|
+
|
36
|
+
## Less simple using build target maps:
|
37
|
+
|
38
|
+
If you wanted a particular condition to apply to more than one target you may do something like:
|
39
|
+
|
40
|
+
if (target?(:anrdroid) || target?(:ios)) { ... }
|
41
|
+
|
42
|
+
..but that can get ugly. Instead we have the concept of "build target maps". They are declared in the config.rb:
|
43
|
+
|
44
|
+
set_build_targets({
|
45
|
+
"phonegap" => {
|
46
|
+
:includes => %w[android ios]
|
47
|
+
}
|
48
|
+
})
|
49
|
+
|
50
|
+
..this means that if my current built target is "android", a query like:
|
51
|
+
|
52
|
+
build_target_is?(:phonegap)
|
53
|
+
|
54
|
+
..will be TRUE since "android" is specifed as being 'included' in this phonegap build target.
|
55
|
+
|
56
|
+
NOTE: You cannot "build" the "phonegap" target directly, you would build the "android" and "ios" targets separately. This is here so you can specify conditions that span two or more build targets without having to make complicated "if" statements.
|
57
|
+
|
58
|
+
## Default target
|
59
|
+
|
60
|
+
If no target is specified the target of "default" is assumed.
|
61
|
+
|
62
|
+
## More Examples
|
63
|
+
|
64
|
+
Please see the EXAMPLES directory for more thorough information.
|
65
|
+
|
66
|
+
# Building a target
|
67
|
+
|
68
|
+
Middleman-target doesn't yet properly connect to the CLI portion of Middleman. Instead, to specify a build target you currently use and environment variable named "MIDDLEMAN_BUILD_TARGET".
|
69
|
+
|
70
|
+
To build the target of "aardvark" you would run:
|
71
|
+
|
72
|
+
MIDDLEMAN_BUILD_TARGET=aardvark middleman build
|
73
|
+
|
74
|
+
# TODO:
|
75
|
+
|
76
|
+
* write rdoc
|
77
|
+
* set build target on the command line as "middleman build TARGET"
|
78
|
+
* use app.set instead of always reading ENV for build target
|
79
|
+
* not allowed to use a build target from the command line if that build_target if specified as a first-order entry in set_build_targets()
|
80
|
+
|
81
|
+
# REQUIREMENTS AND INSTALLATION
|
82
|
+
|
83
|
+
Middleman-Target was developed against [MIDDLEMAN] 2.0.15. Compatibility with other versions is not guaranteed. When Middleman 3.0 is released this will likely not work with it.
|
84
|
+
|
85
|
+
## Gem Version Hell
|
86
|
+
|
87
|
+
Because gem authors don't specify minimal and maximal version of dependencies, installing Middleman 2.0.15 can put you in dependency version hell. To rememdy this, install gems in this order:
|
88
|
+
|
89
|
+
gem install multi_json -v="1.0.3"
|
90
|
+
gem install execjs -v="1.2.7"
|
91
|
+
gem install middleman -v="2.0.15"
|
92
|
+
gem install middleman-target
|
93
|
+
|
94
|
+
[MIDDLEMAN]: https://github.com/middleman/middleman/
|
data/examples/config.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
<html>
|
2
|
+
<body>
|
3
|
+
<h1>current build target: <%= build_target %></h1>
|
4
|
+
<h4>build target map: <%= build_targets.inspect %></h4>
|
5
|
+
|
6
|
+
<p>
|
7
|
+
<% if build_target_is?(:foo) %>
|
8
|
+
Foo specific stuff.
|
9
|
+
<% elsif target?(:bar) %>
|
10
|
+
Bar specific stuff.
|
11
|
+
<% else %>
|
12
|
+
The build target <%= build_target %> has no special needs.
|
13
|
+
<% end %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p>
|
17
|
+
<% if target?(:phonegap) %>
|
18
|
+
Specified target is included in "phonegap" target.
|
19
|
+
<% else %>
|
20
|
+
Specified target is not in "phonegap" target.
|
21
|
+
<% end %>
|
22
|
+
</p>
|
23
|
+
|
24
|
+
<p>
|
25
|
+
<% if default_target? || no_target? %>
|
26
|
+
Using the default build target, or no target specified.
|
27
|
+
<% else %>
|
28
|
+
A build target has been specified that is not the default.
|
29
|
+
<% end %>
|
30
|
+
</p>
|
31
|
+
</body>
|
32
|
+
</html>
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Middleman::Features::Target
|
2
|
+
|
3
|
+
class << self
|
4
|
+
def registered(app)
|
5
|
+
app.set :build_targets, {}
|
6
|
+
app.extend ClassMethods
|
7
|
+
app.helpers HelperMethods
|
8
|
+
end
|
9
|
+
alias :included :registered
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def set_build_targets(targets={})
|
14
|
+
raise "#set_build_targets() argument must be a hash" unless targets.class == Hash
|
15
|
+
settings.build_targets = targets
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module HelperMethods
|
20
|
+
DEFAULT_BUILD_TARGET = :default
|
21
|
+
|
22
|
+
def build_targets
|
23
|
+
@build_target ||= settings.build_targets
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_target
|
27
|
+
@middleman_build_target ||= if ENV['MIDDLEMAN_BUILD_TARGET']
|
28
|
+
ENV['MIDDLEMAN_BUILD_TARGET'].downcase.to_sym
|
29
|
+
else
|
30
|
+
DEFAULT_BUILD_TARGET
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_target_is?(target_name)
|
35
|
+
if build_targets.empty?
|
36
|
+
build_target == target_name
|
37
|
+
else
|
38
|
+
if !build_targets[target_name.to_s].nil?
|
39
|
+
if (build_targets[target_name.to_s][:includes] || []).include?(build_target.to_s)
|
40
|
+
return true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
alias :target? :build_target_is?
|
47
|
+
|
48
|
+
def default_target?
|
49
|
+
build_target == DEFAULT_BUILD_TARGET
|
50
|
+
end
|
51
|
+
alias :no_target? :default_target?
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Middleman
|
4
|
+
module Features
|
5
|
+
require 'lib/middleman-target'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class HelperMethodTest
|
10
|
+
include Middleman::Features::Target::HelperMethods
|
11
|
+
end
|
12
|
+
|
13
|
+
class ClassMethodTest
|
14
|
+
include Middleman::Features::Target::ClassMethods
|
15
|
+
end
|
16
|
+
|
17
|
+
###
|
18
|
+
|
19
|
+
describe Middleman::Features do
|
20
|
+
describe Middleman::Features::Target do
|
21
|
+
describe '.registered' do
|
22
|
+
pending "Not sure how to test this guy"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe Middleman::Features::Target::ClassMethods do
|
27
|
+
before(:each) do
|
28
|
+
@base = ClassMethodTest.new
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#set_build_targets' do
|
32
|
+
it 'should set the build_targets setting to be the passed value' do
|
33
|
+
# expect
|
34
|
+
@base.stub!(:settings).and_return(mock('settings'))
|
35
|
+
@base.settings.should_receive(:build_targets=).once.with({:foo => 'bar'})
|
36
|
+
|
37
|
+
# when
|
38
|
+
@base.set_build_targets({:foo => 'bar'})
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should only accept hashes as arguments' do
|
42
|
+
lambda {
|
43
|
+
@base.set_build_targets('string')
|
44
|
+
}.should raise_error(RuntimeError)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe Middleman::Features::Target::HelperMethods do
|
50
|
+
before(:each) do
|
51
|
+
@base = HelperMethodTest.new
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#build_target_is?' do
|
55
|
+
before(:each) do
|
56
|
+
@base.stub!(:settings).and_return(mock('settings', :build_targets => {}))
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should be true if build target matches passed argument' do
|
60
|
+
# given
|
61
|
+
@base.stub!(:build_target).and_return(:foo)
|
62
|
+
|
63
|
+
# expect
|
64
|
+
@base.build_target_is?(:foo).should be_true
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should be false if build target does not match passed argument' do
|
68
|
+
# given
|
69
|
+
@base.stub!(:build_target).and_return(:bar)
|
70
|
+
|
71
|
+
# expect
|
72
|
+
@base.build_target_is?(:foo).should be_false
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should be true if build_targets defines a target that "includes" this target' do
|
76
|
+
# given
|
77
|
+
@base.stub!(:build_target).and_return(:android)
|
78
|
+
|
79
|
+
@base.stub!(:settings).and_return(
|
80
|
+
mock('settings', :build_targets => {
|
81
|
+
"phonegap" => {
|
82
|
+
:includes => %w[android ios]
|
83
|
+
}
|
84
|
+
})
|
85
|
+
)
|
86
|
+
|
87
|
+
# expect
|
88
|
+
@base.build_target_is?(:phonegap).should be_true
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should be false if build_targets is defined but does "include" target in any definition' do
|
92
|
+
# given
|
93
|
+
@base.stub!(:build_target).and_return(:winmo6)
|
94
|
+
|
95
|
+
@base.stub!(:settings).and_return(
|
96
|
+
mock('settings', :build_targets => {
|
97
|
+
"phonegap" => {
|
98
|
+
:includes => %w[android ios]
|
99
|
+
}
|
100
|
+
})
|
101
|
+
)
|
102
|
+
|
103
|
+
# expect
|
104
|
+
@base.build_target_is?(:phonegap).should be_false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#default_target?' do
|
109
|
+
it 'should be true if the current target is the default target' do
|
110
|
+
# given
|
111
|
+
@base.stub!(:build_target).and_return(
|
112
|
+
Middleman::Features::Target::HelperMethods::DEFAULT_BUILD_TARGET
|
113
|
+
)
|
114
|
+
|
115
|
+
# expect
|
116
|
+
@base.default_target?.should be_true
|
117
|
+
end
|
118
|
+
it 'should be false if the current target is not the default target' do
|
119
|
+
# given
|
120
|
+
@base.stub!(:build_target).and_return(:something)
|
121
|
+
|
122
|
+
# expect
|
123
|
+
@base.default_target?.should be_false
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#build_target' do
|
128
|
+
before(:each) do
|
129
|
+
@base.stub!(:settings).and_return(mock('settings', :build_targets => {}))
|
130
|
+
end
|
131
|
+
it 'should return the specified build target if one was given' do
|
132
|
+
# given
|
133
|
+
ENV['MIDDLEMAN_BUILD_TARGET'] = 'something'
|
134
|
+
|
135
|
+
# expect
|
136
|
+
@base.build_target.should == :something
|
137
|
+
end
|
138
|
+
it 'should downcase and symbolize the given build target' do
|
139
|
+
# given
|
140
|
+
ENV['MIDDLEMAN_BUILD_TARGET'] = 'SoMeThInG'
|
141
|
+
|
142
|
+
# expect
|
143
|
+
@base.build_target.should == :something
|
144
|
+
end
|
145
|
+
it 'should return the default build target if one was given' do
|
146
|
+
# given
|
147
|
+
ENV['MIDDLEMAN_BUILD_TARGET'] = nil
|
148
|
+
|
149
|
+
# expect
|
150
|
+
@base.build_target.should == Middleman::Features::Target::HelperMethods::DEFAULT_BUILD_TARGET
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-target
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Matthew Nielsen
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-04-12 00:00:00 -06:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: middleman
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 0
|
30
|
+
- 15
|
31
|
+
version: 2.0.15
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 9
|
44
|
+
- 0
|
45
|
+
version: 2.9.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: Allows you specify different targets for a middleman build so you can build different versions of a site from the same source tree.
|
49
|
+
email: xunker@pyxidis.org
|
50
|
+
executables: []
|
51
|
+
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
extra_rdoc_files: []
|
55
|
+
|
56
|
+
files:
|
57
|
+
- README.md
|
58
|
+
- examples/config.rb
|
59
|
+
- examples/source/index.html.erb
|
60
|
+
- lib/middleman-target.rb
|
61
|
+
- spec/spec.opts
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- spec/lib/middleman-target_spec.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: https://github.com/xunker/middleman-target
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.3.6
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Ability to specify build targets for Middleman projects
|
94
|
+
test_files: []
|
95
|
+
|