Skip to content

Commit

Permalink
Add support for environments
Browse files Browse the repository at this point in the history
As of https://github.com/middleman/middleman/pull/1293/files middleman
splits the notion of `:mode` and `:config`. This PR updates
middleman-blog to also handle this distinction.

This allows generation of blogposts using config for a particular
environment using the `--environment` flag. e.g:

`middleman article 'Awesome new post' --environment blog would look for
config within the `configure :blog do ...` block.

The main gotcha I see is that this requires `Time.zone` to be set in
config.rb also. I wonder though if that is related to one of the various
other date-related issues:
#238,
#191,
#143
  • Loading branch information
eellson committed Jan 27, 2018
1 parent fec110f commit a67ec00
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/middleman-blog/commands/article.rb
Expand Up @@ -64,7 +64,13 @@ def self.source_root
aliases: "-t",
desc: "A list of comma-separated tags for the post"

class_option "environment",
desc: "The environment to generate article for",
default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
type: :string

def article
env = options[:environment].to_s.to_sym

@content = options[:content] || ""
@date = options[ :date ] ? ::Time.zone.parse( options[ :date ] ) : Time.zone.now
Expand All @@ -75,6 +81,7 @@ def article

app = ::Middleman::Application.new do
config[ :mode ] = :config
config[ :environment ] = env
config[ :disable_sitemap ] = true
config[ :watcher_disable ] = true
config[ :exit_before_ready ] = true
Expand Down

0 comments on commit a67ec00

Please sign in to comment.