middleman-targets 1.0.0

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.
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,13 @@
1
+ ################################################################################
2
+ # middleman-targets.rb
3
+ # This file brings in the CLI additions and activates and registers this
4
+ # extension in Middleman.
5
+ ################################################################################
6
+
7
+ require 'middleman-core'
8
+ require_relative 'middleman-targets/commands'
9
+
10
+ Middleman::Extensions.register :MiddlemanTargets, :before_configuration do
11
+ require_relative 'middleman-targets/extension'
12
+ MiddlemanTargets
13
+ end
@@ -0,0 +1,6 @@
1
+ ################################################################################
2
+ # commands.rb
3
+ # This file aggregates all of the elements that extend Middleman's CLI.
4
+ ################################################################################
5
+
6
+ require_relative 'middleman-cli/build_all'
@@ -0,0 +1,281 @@
1
+ ################################################################################
2
+ # extension.rb
3
+ # This file constitutes the framework for the bulk of this extension.
4
+ ################################################################################
5
+ require 'middleman-core'
6
+
7
+ class MiddlemanTargets < ::Middleman::Extension
8
+
9
+ ############################################################
10
+ # Define the options that are to be set within `config.rb`
11
+ # as Middleman *application* (not extension) options.
12
+ ############################################################
13
+ define_setting :target, 'default', 'The default target to process if not specified.'
14
+ define_setting :targets, { :default => { :features => {} } } , 'A hash that defines many characteristics of the target.'
15
+ define_setting :target_magic_images, true, 'Enable magic images for targets.'
16
+ define_setting :target_magic_word, 'all', 'The magic image prefix for asset substitution.'
17
+
18
+
19
+ ############################################################
20
+ # initialize
21
+ ############################################################
22
+ def initialize(app, options_hash={}, &block)
23
+
24
+ super
25
+ app.config[:target] = app.config[:target].to_sym
26
+
27
+ end # initialize
28
+
29
+
30
+ ############################################################
31
+ # after_configuration
32
+ # Handle the --target cli setting.
33
+ #############################################################
34
+ def after_configuration
35
+
36
+ return if app.config[:exit_before_ready]
37
+
38
+ app.config[:target] = app.config[:target].downcase.to_sym
39
+ requested_target = app.config[:target]
40
+ valid_targets = app.config[:targets].each_key.collect { |item| item.downcase}
41
+
42
+ if valid_targets.count < 1
43
+ say 'middleman-targets is activated but there are no targets specified in your', :red
44
+ say 'configuration file.', :red
45
+ exit 1
46
+ end
47
+
48
+ if valid_targets.include?(requested_target)
49
+
50
+ if app.config[:mode] == :server
51
+ say "Middleman will serve using target \"#{requested_target}\".", :blue
52
+ else
53
+ if (build_dir = app.config[:targets][app.config[:target]][:build_dir])
54
+ app.config[:build_dir] = sprintf(build_dir, requested_target)
55
+ else
56
+ app.config[:build_dir] = "#{app.config[:build_dir]} (#{requested_target})"
57
+ end
58
+ say "Middleman will build using target \"#{requested_target}\".", :blue
59
+ say "Build directory is \"#{app.config[:build_dir]}\".", :blue
60
+ end
61
+
62
+ else
63
+
64
+ if requested_target
65
+ say "The target \"#{requested_target}\" is invalid. Use one of these:", :red
66
+ else
67
+ say 'No target has been specified. Use one of these:', :red
68
+ end
69
+ valid_targets.each { |t| say " #{t}", :red }
70
+ exit 1
71
+
72
+ end
73
+
74
+ end # after_configuration
75
+
76
+
77
+ ############################################################
78
+ # Sitemap manipulators.
79
+ # Add new methods to each resource.
80
+ ############################################################
81
+ def manipulate_resource_list(resources)
82
+
83
+ resources.each do |resource|
84
+
85
+ #--------------------------------------------------------
86
+ # valid_features
87
+ # Returns an array of valid features for this page
88
+ # based on the current target, i.e., features that
89
+ # are true for the current target. These are the
90
+ # only features that can be used with frontmatter
91
+ # :target or :exclude.
92
+ #--------------------------------------------------------
93
+ def resource.valid_features
94
+ @app.config[:targets][@app.config[:target]][:features].select { |k, v| v }.keys
95
+ end
96
+
97
+
98
+ #--------------------------------------------------------
99
+ # targeted?
100
+ # Determines if the resource is eligible for
101
+ # inclusion in the current page based on the front
102
+ # matter `target` and `exclude` data fields:
103
+ # - if frontmatter:target is used, the target or
104
+ # feature appears in the frontmatter, and
105
+ # - if frontmatter:exclude is used, the target or
106
+ # enabled feature does NOT appear in the
107
+ # frontmatter.
108
+ #
109
+ # In general you won't use this resource method
110
+ # because resources will already be excluded before
111
+ # you have a chance to check them, and so any
112
+ # leftover resources will always return true for
113
+ # this method.
114
+ #--------------------------------------------------------
115
+ def resource.targeted?
116
+ target_name = @app.config[:target]
117
+ ( !self.data['target'] || (self.data['target'].include?(target_name) || (self.data['target'] & self.valid_features).count > 0) ) &&
118
+ ( !self.data['exclude'] || !(self.data['exclude'].include?(target_name) || (self.data['exclude'] & self.valid_features).count > 0) )
119
+ end
120
+
121
+
122
+ #========================================================
123
+ # ignore un-targeted pages
124
+ # Here we have the chance to ignore resources that
125
+ # don't belong in this build based on front matter
126
+ # options.
127
+ #========================================================
128
+ resource.ignore! unless resource.targeted?
129
+
130
+
131
+ #========================================================
132
+ # ignore non-target images
133
+ # Here we have the chance to ignore images from other
134
+ # targets if :target_magic_images is enabled.
135
+ #========================================================
136
+ if @app.config[:target_magic_images] && resource.content_type && resource.content_type.start_with?('image/')
137
+ targets = @app.config[:targets].keys
138
+ targets.delete(@app.config[:target])
139
+ keep = true
140
+ targets.each { |prefix| keep = keep && File.basename(resource.path) !~ /^#{prefix}\-/i }
141
+ unless keep
142
+ resource.ignore!
143
+ say " Ignoring #{resource.path} because this target is #{@app.config[:target]}.", :yellow
144
+ end
145
+ end
146
+
147
+
148
+ end # resources.each
149
+
150
+ resources
151
+
152
+ end # manipulate_resource_list
153
+
154
+
155
+ ############################################################
156
+ # Helpers
157
+ # Methods defined in this helpers block are available in
158
+ # templates.
159
+ ############################################################
160
+
161
+ helpers do
162
+
163
+ #--------------------------------------------------------
164
+ # target_name
165
+ # Return the current build target.
166
+ #--------------------------------------------------------
167
+ def target_name
168
+ @app.config[:target]
169
+ end
170
+
171
+
172
+ #--------------------------------------------------------
173
+ # target_name?
174
+ # Is the current target `proposal`?
175
+ #--------------------------------------------------------
176
+ def target_name?( proposal )
177
+ @app.config[:target] == proposal.to_sym
178
+ end
179
+
180
+
181
+ #--------------------------------------------------------
182
+ # target_feature?
183
+ # Does the target have the feature `feature`?
184
+ #--------------------------------------------------------
185
+ def target_feature?( feature )
186
+ features = @app.config[:targets][@app.config[:target]][:features]
187
+ features.key?(feature.to_sym) && features[feature.to_sym]
188
+ end
189
+
190
+
191
+ #--------------------------------------------------------
192
+ # target_value( key )
193
+ # Attempts to return arbitrary key values for the
194
+ # current target.
195
+ #--------------------------------------------------------
196
+ def target_value( key )
197
+ target_values = @app.config[:targets][@app.config[:target]]
198
+ target_values.key?(key) ? target_values[key] : nil
199
+ end
200
+
201
+
202
+ #--------------------------------------------------------
203
+ # image_tag
204
+ # Override the built-in version in order to support:
205
+ # - automatic target-specific images. Note that this
206
+ # only works on local files.
207
+ # - target and feature dependent images.
208
+ # - absolute paths
209
+ #--------------------------------------------------------
210
+ def image_tag(path, params={})
211
+ params.symbolize_keys!
212
+
213
+ # We won't return an image at all if a :target or :feature parameter
214
+ # was provided, unless we're building that target or feature.
215
+ return if params.include?(:target) && !target_name?(params[:target])
216
+ return if params.include?(:feature) && !target_feature?(params[:feature])
217
+
218
+ params.delete(:target)
219
+ params.delete(:feature)
220
+
221
+
222
+ # Let's try to find a substitutable file if the current image name
223
+ # begins with the :target_magic_word
224
+ if @app.config[:target_magic_images] && File.basename(path).start_with?( @app.config[:target_magic_word])
225
+ real_path = path.dup
226
+
227
+ # Enable absolute paths, too.
228
+ real_path = if path.start_with?('/')
229
+ File.expand_path(File.join(@app.config[:source], real_path))
230
+ else
231
+ File.expand_path(File.join(@app.config[:source], @app.config[:images_dir], real_path))
232
+ end
233
+
234
+ proposed_file = real_path.sub( "#{@app.config[:target_magic_word]}-", "#{app.config[:target]}-" )
235
+ file = app.files.find(:source, proposed_file)
236
+
237
+ # Now, only make the change *if* the file exists on disk.
238
+ if file && file[:full_path].exist?
239
+ path = path.dup.sub("#{@app.config[:target_magic_word]}-", "#{app.config[:target]}-")
240
+
241
+ # Support automatic alt tags for absolute locations, too. Only do
242
+ # this for absolute paths; let the extension do its own thing
243
+ # otherwise.
244
+ if @app.extensions[:automatic_alt_tags] && path.start_with?('/')
245
+ alt_text = File.basename(file[:full_path].to_s, '.*')
246
+ alt_text.capitalize!
247
+ params[:alt] ||= alt_text
248
+ end
249
+
250
+ end
251
+ end
252
+
253
+ super(path, params)
254
+ end
255
+
256
+
257
+ end #helpers
258
+
259
+
260
+ ############################################################
261
+ # say
262
+ # Output colored messages using ANSI codes.
263
+ ############################################################
264
+ def say(message = '', color = :reset)
265
+ colors = { :blue => "\033[34m",
266
+ :cyan => "\033[36m",
267
+ :green => "\033[32m",
268
+ :red => "\033[31m",
269
+ :yellow => "\033[33m",
270
+ :reset => "\033[0m",
271
+ }
272
+
273
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
274
+ puts message
275
+ else
276
+ puts colors[color] + message + colors[:reset]
277
+ end
278
+ end # say
279
+
280
+
281
+ end # class MiddlemanTargets
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module MiddlemanTargets
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'middleman-targets/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'middleman-targets'
7
+ s.version = Middleman::MiddlemanTargets::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Jim Derry']
10
+ s.email = ['balthisar@gmail.com']
11
+ s.homepage = 'https://github.com/middlemac/middleman-targets'
12
+ s.summary = 'Provides multiple build targets and tools for Middleman.'
13
+ s.description = 'Provides multiple build targets and tools for Middleman.'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+
21
+ # The version of middleman-core your extension depends on
22
+ s.add_runtime_dependency('middleman-core', ['~> 4.1', '>= 4.1.6'])
23
+
24
+ # Additional dependencies
25
+ s.add_runtime_dependency('middleman-cli', ['~> 4.1', '>= 4.1.6'])
26
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-targets
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jim Derry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.1.6
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.1.6
33
+ - !ruby/object:Gem::Dependency
34
+ name: middleman-cli
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 4.1.6
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '4.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 4.1.6
53
+ description: Provides multiple build targets and tools for Middleman.
54
+ email:
55
+ - balthisar@gmail.com
56
+ executables:
57
+ - middleman-targets
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - CHANGELOG.md
63
+ - Gemfile
64
+ - LICENSE.md
65
+ - README.md
66
+ - Rakefile
67
+ - bin/middleman-targets
68
+ - documentation_project/.gitignore
69
+ - documentation_project/Gemfile
70
+ - documentation_project/README.md
71
+ - documentation_project/config.rb
72
+ - documentation_project/source/frontmatter.html.md.erb
73
+ - documentation_project/source/helpers-resources.html.md.erb
74
+ - documentation_project/source/images/free-logo-small.png
75
+ - documentation_project/source/images/free-logo-small@2x.png
76
+ - documentation_project/source/images/free-logo.png
77
+ - documentation_project/source/images/free-logo@2x.png
78
+ - documentation_project/source/images/pro-logo-small.png
79
+ - documentation_project/source/images/pro-logo-small@2x.png
80
+ - documentation_project/source/images/pro-logo.png
81
+ - documentation_project/source/images/pro-logo@2x.png
82
+ - documentation_project/source/index.html.md.erb
83
+ - documentation_project/source/javascripts/all.js
84
+ - documentation_project/source/layouts/layout.haml
85
+ - documentation_project/source/layouts/template-logo-large.haml
86
+ - documentation_project/source/layouts/template-logo-medium.haml
87
+ - documentation_project/source/layouts/template-logo-small.haml
88
+ - documentation_project/source/only-free.html.md.erb
89
+ - documentation_project/source/only-pro.html.md.erb
90
+ - documentation_project/source/simple-demo.html.md.erb
91
+ - documentation_project/source/stylesheets/_github.scss
92
+ - documentation_project/source/stylesheets/_middlemac_minimal.scss
93
+ - documentation_project/source/stylesheets/_normalize.scss
94
+ - documentation_project/source/stylesheets/style.css.scss
95
+ - documentation_project/source/target-feature-config.html.md.erb
96
+ - lib/middleman-targets.rb
97
+ - lib/middleman-targets/commands.rb
98
+ - lib/middleman-targets/extension.rb
99
+ - lib/middleman-targets/version.rb
100
+ - middleman-targets.gemspec
101
+ homepage: https://github.com/middlemac/middleman-targets
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.8
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Provides multiple build targets and tools for Middleman.
125
+ test_files: []
126
+ has_rdoc: