0

I'm porting the Gulp Starter Rails helpers to Middleman but am getting the following error:

no implicit conversion of Symbol into String related to Ruby /middleman-gulp-starter/helpers/gulp_asset_helper.rb: in join, line 14

I'm not sure of the differences between Rails and Middleman to understand why this isnt working.

module GulpAssetHelper
  def gulp_asset_path(path, type = nil)
    rev_manifest = nil

    # In development, check for the manifest every time
    if !config[:build]
      rev_manifest = JSON.parse(File.read(REV_MANIFEST_PATH)) if File.exist?(REV_MANIFEST_PATH)
    # In production, use the manifest cached in initializers/gulp.rb
    else
      rev_manifest = REV_MANIFEST if defined?(REV_MANIFEST)
    end

    root = GULP_CONFIG['root']['dest'].gsub(/(.*)build\//, '/')
    asset_path = type ? File.join(GULP_CONFIG['tasks'][type]['dest'], path) : path # LINE 14
    asset_path = rev_manifest[asset_path] if rev_manifest
    asset_path = File.join(root, asset_path)
    File.absolute_path(asset_path, '/')
  end

  def gulp_js_path(path)
    gulp_asset_path(path, 'js')
    GULP_CONFIG
  end

  def gulp_css_path(path)
    gulp_asset_path(path, 'css')
  end

  def gulp_image_path(path)
    gulp_asset_path(path, 'images')
  end

  def sprite(id, classes = "", viewBox = "0 0 24 24")
    "<svg class='sprite -#{id} #{classes}' aria-hidden='true' preserveAspectRatio viewBox='#{viewBox}'><use xlink:href='#{gulp_image_path('sprites.svg')}##{id}' /></use></svg>".html_safe
  end
end

The rev and config import file:

GULP_CONFIG = JSON.parse(File.read('gulpfile.js/config.json'))
REV_MANIFEST_PATH = File.join(GULP_CONFIG['root']['dest'], 'rev-manifest.json')

if File.exist?(REV_MANIFEST_PATH)
  REV_MANIFEST = JSON.parse(File.read(REV_MANIFEST_PATH))
end

Example rev-manifest.json file:

{
  "images/middleman-logo.svg": "images/middleman-logo-2e3d8b5ad1.svg",
  "javascripts/all.js": "javascripts/all-92681c51e741e0e1370c.js",
  "stylesheets/site.css": "stylesheets/site-9b25f1d1ac.css"
}

I've output the contents of the gulpfile so know that it is being read correctly.

You can find the full repo here: https://github.com/craigmdennis/middleman-gulp-starter/tree/4_asset-helpers

Craig
  • 972
  • 3
  • 13
  • 38

1 Answers1

1

it looks like it fails on this line:

 asset_path = type ? File.join(GULP_CONFIG['tasks'][type]['dest'], path) : path

The File.join method expect strings so either the GULP_CONFIG['tasks'][type]['dest'] or path is not a string but a symbol. Try something like this:

asset_path = type ? File.join(GULP_CONFIG['tasks'][type.to_s]['dest'].to_s, path.to_s) : path.to_s
Jiri Kremser
  • 12,471
  • 7
  • 45
  • 72