1

I would like to exclude a specific folder from assets/javascripts in my application.html.haml

The folder that I do not want to be included in my layout is mobile folder

Here's my layout:

%html(lang="en")
  %head
    %meta(charset="utf-8")
    %meta(http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1")
    %meta(name="viewport" content="width=device-width, initial-scale=1.0")
    %title= content_for?(:title) ? yield(:title) : @user.name ? 'Niche | ' + @user.name : 'Niche'
    = csrf_meta_tags
    = analytics_init if Rails.env.production?
    / Le HTML5 shim, for IE6-8 support of HTML elements
    /[if lt IE 9]
      = javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js"
    = stylesheet_link_tag "application", :media => "all"

  %body#profile

    %section.persist-area
      %header.global.profile
        %div.container
          %a.brand.pull-left{ :href => root_path }
            .logo-niche


          %nav.pull-right
            = render 'layouts/menu'

      .container-fluid#main
        = yield :profile

      /
        Javascripts
        \==================================================
      / Placed at the end of the document so the pages load faster
      = javascript_include_tag "application"
      = yield :javascript

In this snippet, I am getting all JS:

= javascript_include_tag "application"

But I want to get all JS except the folder named mobile

I tried the following workaround but did not work:

= javascript_include_tag "application", except: "mobile"

Sorry that was just a wild guess. There's no javascript_exclude_tag too as per the docs.

Any ideas? Thanks.

PS: I have a different layout for mobile, so that's why I really want to exclude that folder in desktop view. It's conflicting a lot of conflicts in my desktop view.

xirukitepe
  • 1,575
  • 7
  • 26
  • 54

1 Answers1

1

Change in application.js

//= require_tree

to

//= require_directory .

or

//= require_tree ./useful

So that, app/assets/javascripts/* files will be included and app/assets/javascripts/mobile/* wont be included.

beck03076
  • 3,268
  • 2
  • 27
  • 37
  • So then... other folders will not be required (e.g. I also have a lib folder)? Is there any way to exclude just one folder? Thanks btw for the reply. – xirukitepe Dec 04 '13 at 20:47
  • I would do "//= require_tree ./useful" and under useful, all folders and files that I require will be kept. "/mobile" will be excluded. Here I assume 2 folders in my "app/assets/javascripts", "mobile and useful" – beck03076 Dec 04 '13 at 20:51
  • Thanks for the answer but I used `stub` as well. Just for additional info, if others encounter this problem: http://stackoverflow.com/questions/7602393/rails-3-1-sprockets-require-directives-is-there-a-way-to-exclude-particular-fi – xirukitepe Dec 04 '13 at 21:00