I added sass-grails-asset-pipeline, and in main.gsp I have this:
<asset:stylesheet src="application.css"/>
If I change stylesheets/application.css to stylesheets/application.scss, the GSP produced creates no <link> to request the css. If I do a manual request for http://localhost:8080/my-app/assets/application.css I get a 404.
What's going on? Is there some special undocumented setup to get SCSS working properly?
Make sure you're using a sass-assets plugin that exactly matches your assets-plugin. Mismatching will cause issues.
Related
I just followed the instructions on https://github.com/bmuschko/grails-google-visualization/wiki/usage ... However, I now get the following error:
org.grails.taglib.GrailsTagException: [views/participant/results.gsp:57] Template not found for name [/visualization_javascript] and path [/_visualization_javascript.gsp]
I wonder how I could verify that the google-visualization plugin has been installed correctly. Obviously, it finds the corresponding taglib but not the required template, or am I mistaken?
In my view I have simply put the line <gvisualization:pieCoreChart elementId="piechart" title="My Daily Activities" columns="${columns}" data="${rows}" />. And in the head of the gsp I put <gvisualization:apiImport/>.
Would be grateful for ideas or suggestions?
You should put the files _visualization_javascript.gsp and _formatter.gsp
in your views folder, seems like actually they were omitted in the build of the latest plugin.
I have a grails 2.4.3 app that uses the rendering 1.0.0 plugin and asset-pipeline:1.9.9. I can successfully generate a PDF from a GSP, but
There is no styling, so it look like garbage
Every CSS reference in the GSP causes java.io.IOException: Stream closed to show up in the logs
When I comment out all CSS references, there are no errors, but it still looks like garbage. I believe the stream closed problem is due to the XHTML parser not being able to load the CSS file. The CSS references look like this
<link rel="stylesheet" href="/Invoicer/assets/invoicer.css?compile=false" />
When I load up that URL in the browser, the CSS file is successfully returned and displayed.
I'm also using Spring Security and thought that maybe it was an authentication issue. I removed all of the filters in Config.groovy, so it looks like this
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
'/**': ['permitAll']
]
but that did not help. Any ideas? Thanks!
After re-reading the documentation, I noticed this:
The rendering engine resolves all relative links relative to the
grails.serverURL config property.
I figured serverURL would have been set automatically, but it wasn't. I set
grails.serverURL = "http://localhost:9090/${appName}"
in Config.groovy as well as
grails.server.port.http = 9090
in BuildConfig.groovy. It also appears that they layout engine is not getting called, so I had to manually pull in the CSS files:
<asset:stylesheet src="invoicer.css" />
Here is an answer, but it's ugly. I noticed that specifying the full path to the CSS indeed did work:
<link rel="stylesheet" href="http://localhost:9090/Invoicer/assets/bootstrap.css?compile=false" />
Now, since I'm using asset-pipeline, I have to make asset-pipeline use an absolute URL in Config.groovy:
grails.assets.url = "http://localhost:9090/Invoicer/assets/"
Not pretty, but it will work for now.
Everyone knows how to use stylesheet_link_tag to link to a stylesheet, but I would like to actually include an entire stylesheet in a page itself. (No, this is normally not a great practice, but it makes sense in this context.)
stylesheet_include_tag does not exist, and a co-worker who is a much bigger bad-ass at Rails than I am says there isn’t a simple way.
Question:
Is it actually possible to make use of the asset pipeline and still embed the contents of a CSS or JavaScript file (compiled from Sass or CoffeeScript!) into a .haml view? How?
Added for clarity:
I’d like for my layout to be able to include something like:
= stylesheet_link_tag "base"
= stylesheet_embed_tag "page-specific-styles/foo"
And have this generate output HTML along these lines:
<link rel="stylesheet" href="/base.css" />
<style type="text/css">.foo { color: red; }</style>
Update
It’s possible to use Sass within Haml if you set your initalizer correctly, but I cannot seem to #import "foo" from this context, where foo.css.sass is a stylesheet in the asset pipeline. Note that #import "compass" (assuming you have the compass gem) does work.
This looks like (haml):
%style
:sass
#import "foo"
Rails gives an error that "foo" cannot be found, even though it claims to be looking in app/assets/stylesheets (which is where foo.css.sass lives).
So, this feels closer, but still not quite there.
from http://blog.phusion.nl/2011/08/14/rendering-rails-3-1-assets-to-string/ :
YourApp::Application.assets.find_asset('api.css').source
in haml
%style
=raw YourApp::Application.assets.find_asset('foo.css').source
caveats:
I believe this requires asset compilation in production, which can be pretty costly.
If I understand your question correctly, you could add your CSS code to a normal Ruby view file (as a partial), say styles.html.erb.
And then add that to your page upon any condition you want, I think it's the simplest way of looking at it.
Chrome DevTools Autosave doesn’t work with Rails Asset Pipeline. The culprit of the problem is in the assets URLs — I cannot decipher the actual file path by its URL. For example, /assets/application.css may refer to either app/assets/stylesheets/application.css, lib/assets/stylesheets/application.css,
or vendor/assets/stylesheets/application.css.
I wonder, how do I change assets URL to one of the following:
/app/assets/stylesheets/application.css (matches exactly actual file path, perfect solution)
/assets/application.css?source_url=app/assets/stylesheets/application.css (introduces source_url query parameter)
I would appreciate any help writing Rails plugin for that.
Update: I filled an issue to sprockets.
I'll try to get the ball rolling, but I'd have to do a lot more to verify or provide a better answer, so I'll mark this answer community wiki. That way others can answer below and or edit this post.
I've had to set up asset pipelining for Sinatra, and generally speaking, in the latest versions of Sprockets (which is used to provide the asset pipelining in Rails) the Sprockets::Asset class has methods to obtain the path and logical path.
I believe Rails uses the asset_path helper to generate the public facing url from the Sprockets class. This in turn appears to use the AssetPaths#compute_public_path instance method. A good first step would be to modify these parts of the code to add a source_url parameter based on your parsing of the source.pathname. This is assuming that source is an instance of Sprockets::Asset in some form or another.
I'm not quite sure how you expect the source to come from but it's already provided by ActionView::Helpers::AssetTagHelper
http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html
image_tag("rails.png")
# => <img alt="Rails" src="http://assets.example.com/images/rails.png?1230601161" />
stylesheet_link_tag("application")
# => <link href="http://assets.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" />
I am having a wierd error and jQuery not working depending on how the url is written.
if the url is
/index.cfm?show=about-us
all is good. BUT if the url is
/index.cfm/show_about-us
jQuery doesn't seem to load correctly and I get a "$ is not defined" error in fireBug
I can't use the standard ?= query string I need to be able to use the re-write method.
Any ideas are appriciated
Lance
What does your <script src="..."> say? I have a feeling it's looking for /index.cfm/jquery.js which doesn't exist.
Sorry this was a reference issue to the files. Evendently in that re-write sytle the dom is still trying to navigate the file system starting in the /show_about-us/ directory which isn't truely a directory.
That's it. #recursive got it in one.
Consider using the absolute path from the root of your domain in src attributes. For example: <script src="/jquery.js">