0

情况:我必须在“javascripts”原生树枝块中放置许多脚本。

- javascripts 'assets/js/jquery.js' 'assets/js/some1.coffee' 'assets/js/some2.coffee' ...  'assets/js/someN.coffee' output="assets/js/all.js"
    %script( type="text/javascript" src="#{asset_url~(app.environment == 'dev' ? '?'~random() :'' )}" )

如何将每个脚本放在特定的行中?

例子:

- javascripts 'assets/js/jquery.js' 
'assets/js/some1.coffee' 
'assets/js/some2.coffee' ...  
'assets/js/someN.coffee' 
output="assets/js/all.js"
    %script( type="text/javascript" src="#{asset_url~(app.environment == 'dev' ? '?'~random() :'' )}" )

错误:

编译模板期间抛出异常(“非法嵌套:在插值字符串中嵌套是非法的...... bla bla bla ... layout.html.haml”。

请不要提供assets/js/*

4

1 回答 1

1

快速简单:在config.yml(或assetic.yml您导入的文件)中而不是在模板中定义您的资产集合:

assetic:
    assets:
        # An array of named assets (e.g. some_asset, some_other_asset)
        js_collection_one:
            inputs: 
                - assets/js/some1.coffee
                - assets/js/some2.coffee
                # ...

然后在你的haml模板中:

 - javascripts '@js_collection_one' output="assets/js/all.js"
     %script( type="text/javascript" src="#{asset_url~(app.environment == 'dev' ? '?'~random() :'' )}" ) 
于 2013-11-19T13:37:50.747 回答