Giter VIP home page Giter VIP logo

middleman-target's Introduction

Gem Version Build Status Code Climate

Middleman-Target

Middleman-Target is an extension to MIDDLEMAN 3.x.x and greater to allow you to specify a build target and generate the content accordingly.

NOTE: This version is for MIDDLEMAN >= 3.x.x and Ruby >= 1.9.1. For compatibility with Middleman 2.x.x or Ruby 1.8.7, please see version 0.0.1 of this gem.

What you use it for

Middleman-Target is used to build different versions of in your Middleman project depending on the target you specify.

I created Middleman-Target when I was creating a Phonegap/Cordova app and wanted to use the same HTML code base for both iOS and Android and the web. I needed an easy way to say:

  • If I'm inside Phonegap on iOS, do this.
  • If I'm inside Phonegap on Android, do this.
  • If I'm inside Phonegap on iOS or Android do this.
  • If I'm running as a real mobile web site in a real browser (not in Phonegap), do this.

I created the gem to handle cases like that. Then you can specify a target and middleman will build your project according to that target.

Examples

Simple

ERB code:

<p>
  <%# NOTE: target?() is a shorthand alias for build_target_is?() %>
  <% if build_target_is?(:ios) %>
    iOS specific stuff.
  <% elsif target?(:android) %>
    Android specific stuff.
  <% else %>
    The build target <%= build_target %> has no special needs.
  <% end %>
</p>

Output when run with a build target of 'ios':

iOS specific stuff.

..'Android':

Android specific stuff.

..anything else ('blackberry' in this case):

The build target blackberry has no special needs.

Less simple using build target maps:

If you wanted a particular condition to apply to more than one target you may do something like:

if (target?(:anrdroid) || target?(:ios)) { ... }

..but that can get ugly. Instead we have the concept of "build target maps". They are declared in the config.rb:

activate :target do |t|
  t.build_targets = {
    "phonegap" => {
      :includes => %w[android ios]
    }
  }
end

..this means that if my current built target is "android", a query like:

build_target_is?(:phonegap)

..will be TRUE since "android" is specifed as being 'included' in this phonegap build target.

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.

Default target

If no target is specified the target of "default" is assumed.

More Examples

Please see the EXAMPLES directory for more thorough information.

Building a target

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".

To build the target of "aardvark" you would run:

MIDDLEMAN_BUILD_TARGET=aardvark middleman build

Installing in to Middleman tree

Add the following near the top of your config.rb:

require 'rubygems' # may not be needed depending on ruby ver
require 'middleman-target'
activate :target

To specify a build target map, pass a block in to the activate method as:

activate :target do |t|
  t.build_targets = { ... }
end

Please see /examples for a working usage example.

TODO:

  • repace target.build_targets with something more extensible
  • write rdoc
  • validate the hash passed in to set_build_targets()
  • set build target on the command line as "middleman build TARGET"
  • use app.set instead of always reading ENV for build target
  • 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()

Contributing

If there is any thing you'd like to contribute or fix, please:

  • Fork the repo
  • Make your changes
  • Add Cucumber tests for any new functionality
  • Verify all existing tests work properly
  • Make a pull request

The Cucumber features for this project assume the gem is installed, so to make any changes you will need to build and install the gem locally with your changes.

Changes

0.0.8 July 15, 2015

  • Tested with middleman 3.3.12, changed post-install warning to reflect this.
  • Fixes issue 11.

0.0.7

  • Tested with middleman 3.3.7, changed post-install warning to reflect this.
  • Fixes [issue 12[(#12).

0.0.6

  • Removed maximal middleman version requirement. If the version of middleman currently installed in greater than the last-tested version, a post-install warning is given but the installation will succeed.

0.0.5

  • Changed middleman dependency from ~>3.0.11 to >= 3.0.0 and < 3.2

0.0.4

  • Fixes #3

Misc

The middleman-target gem is Copyright 2012-2015 Matthew Nielsen, distributed under the MIT License.

Thanks to jtwalters@github for patches and motivation to add Middleman 3 compatibility.

middleman-target's People

Contributors

bitdeli-chef avatar jtwalters avatar xunker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jtwalters

middleman-target's Issues

Update to MiddleMan 4.x compatibility

Make branch at current master for 3.x compatibility, master moves to 4.x.
Create release tags for new releases.
Consider moving version number to match middleman version number, with our version number embedded. Something like: 4.x.y.a.b.c, where 4, x, and y are middleman version numbers and a, b, and c are our version numbers. Maybe we only need a and b, no c?

Middleman 3.1.0 compatibility

Is this gem compatible with Middleman 3.1.0 ? I have a conflict in my Gemfile where middelman-target depends on middleman ~> 2.0.15.

Modernize Gemspec file

The gemspec is currently hand-build and difficult to maintain.

Update the gemspec file to be one like Bundler creates, where files are added automatically.

A group name should not be a valid target.

Currently, if I set up my target map as

activate :target do |t|
  t.build_targets = {
    "phonegap" => {
      :includes => %w[android ios]
    }
  }
end

I could do this

MIDDLEMAN_BUILD_TARGET=phonegap middleman build

And it would be accepted but would not do what you expected. Need to throw an exception or error if the given target is actually a group.

Incompatible with middleman 3.0

I wanted this functionality in middleman 3, but the extension wasn't compatible. A couple minor changes seems to fix it, although I've only done very limited testing.

Replace #build_targets= with something better

The build_targets syntax is currently this:

activate :target do |t|
  t.build_targets = {
    "phonegap" => {
      :includes => %w[android ios]
    }
  }
end

It could be a lot better. I would like to turn it in to something like this:

activate :target do |t|
  t.groups << "phonegap"
  t.groups.phonegap << "android"
  t.groups.phonegap << "ios"
end

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

  spec.license = 'MIT'
  # or
  spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Validate hash passed in to #build_targets=

Even though issue #4 would supersede the use of #build_targets=, it would need to be there for a few version for compatibility.

It would be nice to validate the hash that is passed it to make sure that it is the correct structure. Currently the only check that is done it so make sure it is a Hash.

activate :target without block results in an error

I get the following error when attempting to run middleman build:

lib/middleman-target/extension.rb:40:in `build_targets': undefined local variable or method `build_target_definitions' for #<Middleman::Application:0x70191144676020> (NameError)

Isn't the build target map block supposed to be optional?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.