middleman: Middleman won't reload helpers when helpers are edited (though it claims to reload itself)

When i edit a helper under /helpers/, Middleman says:

== The Middleman is reloading
== The Middleman has reloaded

But changes in the helper are not applied. I have to restart Middleman manually every time i edit a helper.

Tested on Windows.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 1
  • Comments: 37 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Okay, I might be able to hack it in there ๐Ÿ˜ƒ Let me think about it.

As @tdreyno wrote, require only reads files the first time. However, there is load, which just loads that file each time you call it.

Since config.rb is re-evaluated each time Middleman reboots, this will successfully reload helpers:

# in config.rb:

# Middleman fails to reload helpers, although it notices their modification
# This force-reloads them
Dir['helpers/*'].each(&method(:load))

If you have nested helpers, you need to adapt the glob string to something like 'helpers/**/*'.

@jsoref I replaced require with load in our internal code and added some tests. It seems to work in the base case.

No solution yet?

In the meantime, this is a very crude way to reload middleman when any ruby changes. (There are probably more elegant ways to do this, but itโ€™s what I ended up getting working)

# in the Gemfile
group :development do
  gem "god"
  gem "guard"
end

# in a new file named: middleman.god
# this will start middleman
God.watch do |w|
  w.name = "middleman"
  w.start = "bundle exec middleman server"
  w.keepalive
  w.log = "#{File.expand_path("..", __FILE__)}/middleman.log"
  w.dir = File.expand_path("..", __FILE__)
end

# in a new file named: Guardfile
# this watches for any ruby changes and tells god to restart middleman
# it would be nice to do this all with Guard, but I don't know enough about managing daemons in Guard
require 'guard/plugin'

module ::Guard
  class God < Plugin
    def reload
      reload_god
    end

    def run_on_additions(paths)
      reload_god
    end

    def run_on_modifications(paths)
      reload_god
    end

    def run_on_removals(paths)
      reload_god
    end

    private

    def reload_god
      `god restart`
    end
  end
end

guard 'God' do
  watch(%r{^.+\.rb$})
end
# start god first
$ god -c middleman.god

# then start guard
$ guard -i # you should be good to go at this point

# If you want to close down, CTRL-C guard and then run:
$ god terminate

You can also use guard-middleman which will rebuild the actual html every time something changes, but I just wanted to stick with the ruby server for now.

This is also handy because it will restart whenever lib/ changes