middleman-targets 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/CHANGELOG.md +6 -0
  4. data/Gemfile +18 -0
  5. data/LICENSE.md +22 -0
  6. data/README.md +110 -0
  7. data/Rakefile +10 -0
  8. data/bin/middleman-targets +80 -0
  9. data/documentation_project/.gitignore +25 -0
  10. data/documentation_project/Gemfile +14 -0
  11. data/documentation_project/README.md +13 -0
  12. data/documentation_project/config.rb +123 -0
  13. data/documentation_project/source/frontmatter.html.md.erb +70 -0
  14. data/documentation_project/source/helpers-resources.html.md.erb +98 -0
  15. data/documentation_project/source/images/free-logo-small.png +0 -0
  16. data/documentation_project/source/images/free-logo-small@2x.png +0 -0
  17. data/documentation_project/source/images/free-logo.png +0 -0
  18. data/documentation_project/source/images/free-logo@2x.png +0 -0
  19. data/documentation_project/source/images/pro-logo-small.png +0 -0
  20. data/documentation_project/source/images/pro-logo-small@2x.png +0 -0
  21. data/documentation_project/source/images/pro-logo.png +0 -0
  22. data/documentation_project/source/images/pro-logo@2x.png +0 -0
  23. data/documentation_project/source/index.html.md.erb +59 -0
  24. data/documentation_project/source/javascripts/all.js +1 -0
  25. data/documentation_project/source/layouts/layout.haml +9 -0
  26. data/documentation_project/source/layouts/template-logo-large.haml +17 -0
  27. data/documentation_project/source/layouts/template-logo-medium.haml +14 -0
  28. data/documentation_project/source/layouts/template-logo-small.haml +11 -0
  29. data/documentation_project/source/only-free.html.md.erb +38 -0
  30. data/documentation_project/source/only-pro.html.md.erb +39 -0
  31. data/documentation_project/source/simple-demo.html.md.erb +183 -0
  32. data/documentation_project/source/stylesheets/_github.scss +61 -0
  33. data/documentation_project/source/stylesheets/_middlemac_minimal.scss +516 -0
  34. data/documentation_project/source/stylesheets/_normalize.scss +374 -0
  35. data/documentation_project/source/stylesheets/style.css.scss +3 -0
  36. data/documentation_project/source/target-feature-config.html.md.erb +153 -0
  37. data/lib/middleman-targets.rb +13 -0
  38. data/lib/middleman-targets/commands.rb +6 -0
  39. data/lib/middleman-targets/extension.rb +281 -0
  40. data/lib/middleman-targets/version.rb +5 -0
  41. data/middleman-targets.gemspec +26 -0
  42. metadata +126 -0
@@ -0,0 +1,70 @@
1
+ ---
2
+ title: Front Matter
3
+ layout: template-logo-medium
4
+ ---
5
+
6
+ # Front Matter
7
+
8
+ By default every page in a Middleman project is included in the build output,
9
+ but `middleman-targets` provides means to ensure that only target- and
10
+ feature-specific pages are included. This is controlled by data in your pages’
11
+ front matter.
12
+
13
+ ## `target`
14
+
15
+ The `target` key acts to ensure that _only_ targets and features in its array
16
+ are included in the build. For example:
17
+
18
+ ~~~ erb
19
+ ---
20
+ target:
21
+ - :free
22
+ - :insults_user
23
+ ---
24
+ ~~~
25
+
26
+ This example page would only be built if the target **or** feature is `free`
27
+ or `insults_user`.
28
+
29
+ Note there is no distinction between targets and features in this list. If the
30
+ target is `insults_user` or the feature is `free`, then output will be enabled.
31
+ {:.note}
32
+
33
+
34
+ ## `exclude`
35
+
36
+ The `exclude` key ensures that pages are only built for targets and features
37
+ that do not appear in the `exclude` array. For example:
38
+
39
+ ~~~ erb
40
+ ---
41
+ exclude:
42
+ - :pro
43
+ - :insults_user
44
+ ---
45
+ ~~~
46
+
47
+ This example would build the page, unless the current target or feature were
48
+ `pro` **or** `insults_user`, i.e., either condition prevents the page from
49
+ being output.
50
+
51
+ Note there is no distinction between targets and features in this list. If the
52
+ target is `insults_user` or the feature is `free`, then output will be enabled.
53
+ {:.note}
54
+
55
+
56
+ ## Precedence
57
+
58
+ `exclude` will always override `target`.
59
+
60
+
61
+
62
+ <% content_for :seeAlso do %>
63
+ <ul>
64
+ <li><a href="index.html">Welcome to middleman-targets</a></li>
65
+ <li><a href="simple-demo.html">Simple features demonstration</a></li>
66
+ <li><a href="build-serve-targets.html">Build and Serve different targets</a></li>
67
+ <li><a href="target-feature-config.html">Configuration</a></li>
68
+ <li><a href="helpers-resources.html">Helpers and Resources</a></li>
69
+ </ul>
70
+ <% end %>
@@ -0,0 +1,98 @@
1
+ ---
2
+ title: Helpers and Resources
3
+ layout: template-logo-medium
4
+ ---
5
+
6
+ # Helpers and Resources
7
+
8
+ `middleman-targets` includes some helpers and some page resources that make
9
+ working with multiple targets easier.
10
+
11
+
12
+ ## Resources
13
+
14
+ Middleman’s resource list is available to all of your templates and pages, and
15
+ also available for your own helpers, and `middleman-targets` provides a couple
16
+ of resource map additions than can prove useful when developing your own
17
+ helpers.
18
+
19
+ `valid_features`
20
+
21
+ : `valid_features` returns an array of features that are enabled and applicable
22
+ to the current build target. Although available for output in your pages,
23
+ this is probably most useful for developing your own helpers.
24
+
25
+ By way of example, the raw output of `<%%= current_page.valid_features %>`
26
+ on this page is `<%= current_page.valid_features %>`. The output will be
27
+ different if you switch targets.
28
+
29
+ `targeted?`
30
+
31
+ : Determines if the resource is eligible for inclusion in the current page
32
+ based on the front matter `target` and `exclude` data fields
33
+
34
+ - if `frontmatter:target` is used, the target or feature appears in the
35
+ front matter, and
36
+ - if `frontmatter:exclude` is used, the target or enabled feature does NOT
37
+ appear in the frontmatter.
38
+
39
+ In general you won't use this resource method on pages because resources will
40
+ already be excluded before you have a chance to check them, and so any
41
+ leftover resources will always return true for this method. This method could
42
+ be valuable in writing your own helpers, however.
43
+
44
+
45
+ ## Helpers
46
+
47
+ `target_name`
48
+
49
+ : Return the current build target.
50
+
51
+ `target_name?(proposal)`
52
+
53
+ : Is the current target `proposal`?
54
+
55
+ `target_feature?(feature)`
56
+
57
+ : Does the target have the feature `feature`?
58
+
59
+ `target_value(key)`
60
+
61
+ : Attempts to return the value for they key `key` for the current target.
62
+
63
+ `image_tag`
64
+
65
+ : Extends Middleman’s built-in `image_tag` helper in order to support:
66
+
67
+ - automatic target-specific images. Note that this only works on local files.
68
+ - target and feature dependent images.
69
+ - absolute paths
70
+
71
+ Automatic target-specific images are described in
72
+ [Simple features demonstration](simple-demo.html), and allow you to specify
73
+ an image with a magic prefix in your source code which will be substituted
74
+ with a target-specific image for output.
75
+
76
+ Target- and feature-dependent images add the `:target` and `:feature`
77
+ options to the `image_tag` parameter array, indicating that the image should
78
+ only be used in the condition specified. For example,
79
+ `image_tag 'my_image.png', :feature => 'insults_user'` will only include the
80
+ image if the current target has the feature `insults_user` enabled.
81
+
82
+ As a freebie that’s not specifically related to multiple targets, our
83
+ `image_tag` helper also works with absolute image paths, where ”absolute”
84
+ means relative to your project directory. Specifying `/assets/images/photo.png`
85
+ will correctly reference that image as if your project directory were the
86
+ root filesystem.
87
+
88
+
89
+
90
+ <% content_for :seeAlso do %>
91
+ <ul>
92
+ <li><a href="index.html">Welcome to middleman-targets</a></li>
93
+ <li><a href="simple-demo.html">Simple features demonstration</a></li>
94
+ <li><a href="build-serve-targets.html">Build and Serve different targets</a></li>
95
+ <li><a href="target-feature-config.html">Configuration</a></li>
96
+ <li><a href="frontmatter.html">Front Matter</a></li>
97
+ </ul>
98
+ <% end %>
@@ -0,0 +1,59 @@
1
+ ---
2
+ title: Welcome to middleman-targets
3
+ layout: template-logo-large
4
+ ---
5
+
6
+ <div markdown="1">
7
+
8
+ # Welcome to middleman-targets
9
+
10
+ The `middleman-targets` gem is an extension to [Middleman][1] that gives you the
11
+ ability to specify multiple build targets and provides useful tools for dealing
12
+ with multiple targets and features.
13
+
14
+ - Generate multiple targets for different uses using the same basic project
15
+ structure, content, and code.
16
+ - Assign “features” to targets which give you fine-grained control over what
17
+ content appears in each target.
18
+ - Select images automatically based on the current build target.
19
+ - Use images selectively based on the current build target or feature.
20
+ - Include target-specific versions of data in a consistent fashion.
21
+
22
+ `middleman-targets` was written as part of the [Middlemac][2] Help Book building
23
+ system for Mac OS X applications, but it’s suitable for any project that
24
+ requires multiple build targets, such as software documentation, training
25
+ manuals, and more.
26
+
27
+ This documentation will refer to two sample targets: `:pro` and `:free`, which
28
+ is something that a typical software publisher might do.
29
+
30
+ Note that parts of this documentation will have different content depending on
31
+ whether you are building the `:pro` or `:free` target. These are just examples,
32
+ though, and all of the technical documentation is the same.
33
+ {:.note}
34
+
35
+ * * *
36
+
37
+ - [Simple features demonstration](simple-demo.html)
38
+ - [Build and Serve different targets](build-serve-targets.html)
39
+ - [Configuration](target-feature-config.html)
40
+ - [Helpers and Resources](helpers-resources.html)
41
+ - [Front Matter](frontmatter.html)
42
+
43
+
44
+ </div>
45
+
46
+ [1]: https://middlemanapp.com/
47
+ [2]: https://github.com/middlemac
48
+
49
+
50
+
51
+ <% content_for :seeAlso do %>
52
+ <ul>
53
+ <li><a href="simple-demo.html">Simple features demonstration</a></li>
54
+ <li><a href="build-serve-targets.html">Build and Serve different targets</a></li>
55
+ <li><a href="target-feature-config.html">Configuration</a></li>
56
+ <li><a href="helpers-resources.html">Helpers and Resources</a></li>
57
+ <li><a href="frontmatter.html">Front Matter</a></li>
58
+ </ul>
59
+ <% end %>
@@ -0,0 +1 @@
1
+ // This is where it all goes :)
@@ -0,0 +1,9 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title= current_page.data.title || 'middleman-targets'
5
+ %meta{:content => 'text/html; charset=utf-8', :'http-equiv' => 'Content-Type'}/
6
+ = stylesheet_link_tag 'style'
7
+ = javascript_include_tag 'all'
8
+ %body
9
+ = yield
@@ -0,0 +1,17 @@
1
+ = wrap_layout ('layout'.to_sym) do
2
+ .container-logo-large
3
+ %div
4
+ %div
5
+ = image_tag 'all-logo-small.png', :alt => 'middleman-targets logo'
6
+ %h1= "#{product_name}"
7
+ %h2= "version #{product_version}"
8
+ %a{:href => product_uri}= product_uri
9
+
10
+ - if content_for?(:seeAlso)
11
+ .related_topics
12
+ %h1 See Also
13
+ = yield_content :seeAlso
14
+
15
+ %div
16
+ .yield-content
17
+ ~ yield
@@ -0,0 +1,14 @@
1
+ = wrap_layout ('layout'.to_sym) do
2
+ .container-logo-medium
3
+ %div
4
+ .yield-content
5
+ ~ yield
6
+
7
+ %div
8
+ %div
9
+ = image_tag 'all-logo-small.png', :alt => 'middleman-targets logo'
10
+ .related_topics
11
+
12
+ - if content_for?(:seeAlso)
13
+ %h1 See Also
14
+ = yield_content :seeAlso
@@ -0,0 +1,11 @@
1
+ = wrap_layout ('layout'.to_sym) do
2
+ .container-logo-small
3
+ .yield-content
4
+ = image_tag 'all-logo-small.png', :alt => 'middleman-targets logo'
5
+ ~ yield
6
+
7
+ .related_topics
8
+ - if content_for?(:seeAlso)
9
+ %hr
10
+ %h1 See Also
11
+ = yield_content :seeAlso
@@ -0,0 +1,38 @@
1
+ ---
2
+ title: Only for :free
3
+ layout: template-logo-small
4
+ target:
5
+ - :free
6
+ ---
7
+
8
+ # Only for :free
9
+
10
+ This page is only available to the `:free` target, and no other target will make
11
+ this page available during build or while running the server.
12
+
13
+ This is accomplished by using the `target` key in the
14
+ [front matter](frontmatter.html) data, and specifying only the `:free` target.
15
+
16
+ ~~~ erb
17
+ ---
18
+ title: Only for :free
19
+ layout: template-logo-small
20
+ target:
21
+ - :free
22
+ ---
23
+ ~~~
24
+
25
+ Note that `target` is a YAML array; you can include multiple `target` targets
26
+ and/or features here.
27
+ {:.note}
28
+
29
+ <% content_for :seeAlso do %>
30
+ <ul>
31
+ <li><a href="index.html">Welcome to middleman-targets</a></li>
32
+ <li><a href="simple-demo.html">Simple features demonstration</a></li>
33
+ <li><a href="build-serve-targets.html">Build and Serve different targets</a></li>
34
+ <li><a href="target-feature-config.html">Configuration</a></li>
35
+ <li><a href="helpers-resources.html">Helpers and Resources</a></li>
36
+ <li><a href="frontmatter.html">Front Matter</a></li>
37
+ </ul>
38
+ <% end %>
@@ -0,0 +1,39 @@
1
+ ---
2
+ title: Only for :pro
3
+ layout: template-logo-small
4
+ exclude:
5
+ - :free
6
+ ---
7
+
8
+ # Only for :pro
9
+
10
+ This page is only available to targets that are not `:free`; in this sample
11
+ project, that means that only the `:pro` target will make this page available
12
+ during build or while running the server.
13
+
14
+ This is accomplished by using the `exclude` key in the
15
+ [front matter](frontmatter.html) data, and excluding the `:free` target.
16
+
17
+ ~~~ erb
18
+ ---
19
+ title: Only for :pro
20
+ layout: template-logo-small
21
+ exclude:
22
+ - :free
23
+ ---
24
+ ~~~
25
+
26
+ Note that `exclude` is a YAML array; you can include multiple `exclude` targets
27
+ and/or features here.
28
+ {:.note}
29
+
30
+ <% content_for :seeAlso do %>
31
+ <ul>
32
+ <li><a href="index.html">Welcome to middleman-targets</a></li>
33
+ <li><a href="simple-demo.html">Simple features demonstration</a></li>
34
+ <li><a href="build-serve-targets.html">Build and Serve different targets</a></li>
35
+ <li><a href="target-feature-config.html">Configuration</a></li>
36
+ <li><a href="helpers-resources.html">Helpers and Resources</a></li>
37
+ <li><a href="frontmatter.html">Front Matter</a></li>
38
+ </ul>
39
+ <% end %>
@@ -0,0 +1,183 @@
1
+ ---
2
+ title: Simple features demonstration
3
+ layout: template-logo-medium
4
+ ---
5
+
6
+ # Simple features demonstration
7
+
8
+ This page demonstrates most of the features provided by `middleman-targets`.
9
+ Notably on this page (as on all others) you can see that the logo reflects
10
+ the current target. If you build or serve `:pro` you will see the logo text
11
+ differently than building or serving `:free`.
12
+
13
+ This is accomplished by using the enhanced `image_tag`
14
+ [helper](helpers-resources.html) and specifying an image with a magic prefix (in
15
+ this project the prefix is `all-`).
16
+
17
+
18
+ ## Current target
19
+
20
+ Your current `target_name` is `<%= target_name %>`, and this `<%= target_name %>`
21
+ output is a result of the `target_name` [helper](helpers-resources.html).
22
+
23
+ This in itself isn’t so useful; your users probably don’t care about the
24
+ internal names for your targets. However…
25
+
26
+
27
+ ## Target based conditions
28
+
29
+ You can vary the output per target using simple conditional expressions in
30
+ whatever template language you use. Since the source for this page is an ERB
31
+ file, let’s show an example using ERB:
32
+
33
+ <% if target_name?(:pro) %>
34
+ **You are viewing the `pro` target.**
35
+ <% else %>
36
+ **You are viewing the `free` target.**
37
+ <% end %>
38
+ {:.note}
39
+
40
+ This output is a result of this conditional in the source file:
41
+
42
+ ~~~ erb
43
+ <%% if target_name?(:pro) %>
44
+ **You are viewing the `pro` target.**
45
+ <%% else %>
46
+ **You are viewing the `free` target.**
47
+ <%% end %>
48
+ ~~~
49
+
50
+ If you only have a few targets without a large variety of feature differences,
51
+ then using target based conditions may be ideal for you. However as things tend
52
+ to become more complex, micromanaging which content belongs to which feature
53
+ tends to become unmanageable.
54
+
55
+
56
+ ## Feature based conditions
57
+
58
+ Applying content based on feature gives you much greater flexibility and control
59
+ over what content is included in your builds. The concept is simple: add an
60
+ identical list of features to each target in your [`config.rb`](target-feature-config.html)
61
+ file, and then either enable them (`true`) or disable them (`false`) for each
62
+ target.
63
+
64
+ For example, the `config.rb` for this project includes the feature
65
+ `feature_advertise_pro`, which is something that might be reasonable to include
66
+ in your free project but unnecessary in your professional project, e.g.:
67
+
68
+ <% if target_feature?(:feature_advertise_pro) %>
69
+ Did you know that the Professional version of project has an even better message
70
+ for you?
71
+ <% else %>
72
+ As a thank you to our valued, paying customers we offer you, well, thanks!
73
+ <% end %>
74
+ {:.note}
75
+
76
+ The notice above was produced with this simple code:
77
+
78
+ ~~~ erb
79
+ <%% if target_feature?(:feature_advertise_pro) %>
80
+ As a thank you to our valued, paying customers we offer you, well, thanks!
81
+ <%% else %>
82
+ Did you know that the Professional version of project has an even better message
83
+ for you?
84
+ <%% end %>
85
+ ~~~
86
+
87
+ Managing your content with features instead of targets can make it dead simple
88
+ to change your documentation in the event that your product features change.
89
+
90
+
91
+ ## Target specific data
92
+
93
+ This project’s [`config.rb`](target-feature-config.html) defines a sample data
94
+ key called `sample_key` containing a different message for each target.
95
+
96
+ <%= @app.config[:targets][@app.config[:target]][:sample_key] %>
97
+ {:.note}
98
+
99
+ That output was generated with this code:
100
+
101
+ ~~~ erb
102
+ <%%= @app.config[:targets][@app.config[:target]][:sample_key] %>
103
+ ~~~
104
+
105
+ However that’s a bit fussy, and could be output much more easily by using a
106
+ built-in [helper](helpers-resources.html):
107
+
108
+ <%= target_value(:sample_key) %>
109
+ {:.note}
110
+
111
+ ~~~ erb
112
+ <%%= target_value(:sample_key) %>
113
+ ~~~
114
+
115
+
116
+ ## Omitting pages
117
+
118
+ Using [frontmatter data](frontmatter.html) you can selectively include and/or
119
+ exclude entire pages from your project based on target and/or features. The
120
+ two links (but not destinations) that follow are present in both the `:pro`
121
+ and `:free` targets, but depending on which target you are viewing the
122
+ destination will not be present.
123
+
124
+ - [Link to a `:free`-only page](only-free.html)
125
+ - [Link to a `:pro`-only page](only-pro.html)
126
+
127
+ Code revealing how this is done is present on those two pages.
128
+
129
+
130
+ ## Target and feature specific images
131
+
132
+ Our `image_tag` helper adds the `:target` and `:feature` parameters to the
133
+ built-in helper which is intended as a space-saver compared to
134
+ `<%% if target_name?(…) %>` and `<%% if target_feature?(…) %>` conditional
135
+ blocks. Simply supply the desired target or feature in the options parameter
136
+ and the image will be included or excluded appropriately.
137
+
138
+ <%= image_tag 'pro-logo-small.png', :target => 'pro' %>
139
+ <%= image_tag 'free-logo-small.png', :target => 'free' %>
140
+
141
+ You will see an appropriate version of the logo based on this code:
142
+
143
+ ~~~ erb
144
+ <%%= image_tag 'pro-logo-small.png', :target => 'pro' %>
145
+ <%%= image_tag 'free-logo-small.png', :target => 'free' %>
146
+ ~~~
147
+
148
+ However in the case of target based image selection, there’s an even easier
149
+ way…
150
+
151
+
152
+ ## Automatic target based images
153
+
154
+ By specifying a magic prefix defined in your [`config.rb`](target-feature-config.html)
155
+ file, you can enable automatic substitution of images based on the current
156
+ build target. For example:
157
+
158
+ <%= image_tag 'all-logo-small.png' %>
159
+
160
+ The above, target-appropriate image was produced with this single line of code:
161
+
162
+ ~~~ erb
163
+ <%%= image_tag 'all-logo-small.png' %>
164
+ ~~~
165
+
166
+ If you look at the `images/` directory in this project’s source, you’ll notice
167
+ that there’s not even a file named `all-logo-small.png`.
168
+
169
+ Do note, however, that this automatic substitution _only_ works for images that
170
+ are located within your project’s directory, and not from assets not available
171
+ in the file system.
172
+ {:.note}
173
+
174
+
175
+ <% content_for :seeAlso do %>
176
+ <ul>
177
+ <li><a href="index.html">Welcome to middleman-targets</a></li>
178
+ <li><a href="build-serve-targets.html">Build and Serve different targets</a></li>
179
+ <li><a href="target-feature-config.html">Configuration</a></li>
180
+ <li><a href="helpers-resources.html">Helpers and Resources</a></li>
181
+ <li><a href="frontmatter.html">Front Matter</a></li>
182
+ </ul>
183
+ <% end %>