I have guard (the ruby gem) setup and working it seems on my Mac and setting up a guard from guard-coffee and guard-shell seem to work fine. Here is the related section of my Guardfile below
guard 'coffeescript', :input => 'src/javascripts', :output => 'public/javascripts'
guard 'shell' do
watch( %r{^public/.+\.(js|css)$} ) do |m|
puts m.inspect
if m[1] == 'js'
puts 'a js is new!'
else
puts 'a css is new!'
end
puts %x{ echo #{File.mtime(m[0])} }
end
end
Which seems to output 'a js is new' twice if I edit a coffeescript file. With debug on it seems to run after
13:39:23 - DEBUG - Hook :run_on_changes_begin executed for Guard::CoffeeScript
13:39:23 - INFO - Compile src/javascripts/blah.coffee
13:39:23 - INFO - 01:39:23 PM Successfully generated public/javascripts/blah.js
["public/javascripts/blah.js", "js"]
a js is new!
and
13:39:23 - DEBUG - Hook :run_on_changes_end executed for Guard::CoffeeScript
["public/javascripts/blah.js", "js"]
a js is new!
It does seem to only fire once if I edit the blah.js file directly. I was a little confused by how hooks work, can I key into a hook from another guard? Should I just run this code in a callback in the coffeescript guard? I was trying to use groups and only do the shell part if I was in a group and didn't want to have to repeat the coffee guard in the case where I would use a callback instead.
Any thoughts on how I can stop triggering the shell guard twice when the coffe one fires?
Prior to Guard 1.0.0, new files created and updated from a Guard plugin did not trigger a subsequent file change for other plugins. This was a problem for example with the CoffeeScript and LiveReload plugins: When a JavaScript file has been updated, then LiveReload did not reload the file. As a workaround I added some manual file trigger code. With the Listen gem this limitation has been removed, thus the CoffeeScript plugin triggers file changes twice.
I removed it on my master branch. Can you please give it a try before I release a new gem? You can do this easily by using my master branch by adding:
gem 'guard-coffeescript', :github => 'netzpirat/guard-coffeescript', :branch => 'master'
to your Gemfile. I'll release a new gem asap when it works fine.
Related
I am trying to use ckeditor (4.0.6) with Using rails_admin (0.5.0) in Rails 4.0 on DigitalOcean server.
I have included it in the rails_admin.rb initializer as follows and it works in production mode on my local
config.model Faq do
field :display_order
field :question
field :answer, :ck_editor
end
However on DigitalOcean when I go into Rails_Admin and try to make a new FAQ object it won't load ckeditor because it can't find the js.
http://dummy.com/assets/ckeditor/ckeditor.js?_=1381313244552 404 (Not Found)
rails_admin-5daa9b7b76a226bdfa46a07fdaf2d77d.js:3
How can I fix this?
The problem is because Rails assets compile actually added a fingerprint on to the assets file of every CKeditor file, while the rails-admin is looking for a non fingerprint version of the file.
This issue only happens in the rails 4 with ckeditor. Actually the Readme.md of the ckeditor gem did mention about the issue and how to resolve it, but it isn't complete.
To resolve you could write a rake file to remove all the fingerprints and run this during deployment.
Here is my solution to resolve this issue.
Create a rake file in lib/tasks/ckeditor.rake with the following code
namespace :ckeditor do
desc 'Create nondigest versions of some ckeditor assets (e.g. moono skin png)'
task :create_nondigest_assets do
fingerprint = /\-[0-9a-f]{32}\./
for file in Dir[File.join('public/assets/ckeditor', '**', '*.js'),
File.join('public/assets/ckeditor', '**', '*.js.gz'),
File.join('public/assets/ckeditor', '**', '*.css'),
File.join('public/assets/ckeditor', '**', '*.png'),
File.join('public/assets/ckeditor', '**', '*.gif')]
next unless file =~ fingerprint
nondigest = file.sub fingerprint, '.' # contents-0d8ffa186a00f5063461bc0ba0d96087.css => contents.css
FileUtils.cp file, nondigest, verbose: true
end
end
end
For Capistrano user, make sure you include this in your deploy.rb
desc 'copy ckeditor nondigest assets'
task :copy_nondigest_assets, roles: :app do
run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} ckeditor:create_nondigest_assets"
end
after 'deploy:assets:precompile', 'copy_nondigest_assets'
For Heroku user, you would need to run the rake file manually each time before you check in your code. Make sure you do your rake assets:precompile before this.
rake ckeditor:create_nondigest_assets
Hope it helps
I don't know, have you precompiled your assets?
If you're switching from a different kind of host, like Heroku, you
may forget that you have to manually precompile your assets. You're
lucky, though – it's easy!
RAILS_ENV=production rake assets:precompile If you run into problems,
try running this instead:
RAILS_ENV=production rake assets:precompile:primary
From https://www.digitalocean.com/community/articles/how-to-launch-your-ruby-on-rails-app-with-the-digitalocean-one-click-image
I'm trying to use guard livereload and guard compass together. Here is my file
A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'compass' do
watch('^sass/(.*)\.s[ac]ss')
end
guard 'livereload' do
watch(%r{.+\.(css|html|js)$})
end
# This will concatenate the javascript files specified in :files to public/js/all.js
#guard :concat, type: "js", files: %w(), input_dir: "public/js", output: "public/js/all"
#guard :concat, type: "css", files: %w(), input_dir: "public/css", output: "public/css/all"
#guard 'uglify', :destination_file => "public/javascripts/application.js" do
# watch (%r{app/assets/javascripts/application.js})
#end
When i begin to guard, without enabling the chrome live reload extension, my sass files are compiled and work well.
But when I enable the livereload extension, my terminal says that browser is connected, and then when i make changes in my sass files, nothing happens (neither the page reloads, nor the sass files are compiled).
Does anyone have any ideas ?
For the moment, I'm lauching two terminals in windows, one where I do compass watch, and one where I do guard (I commented the compass part of the GuardFile).
If someone has a better solution
This is how I do it and works perfectly.
puts "Using default guard file."
group :development do
if File.exists?("./config.rb")
# Compile on start.
puts `compass compile --time --quiet`
# https://github.com/guard/guard-compass
guard :compass do
watch(%r{(.*)\.s[ac]ss$})
end
end
guard :livereload, :host => '127.0.0.1', :port => '35729', :grace_period => 0.5 do
watch(%r{.+\.(css|js|html?|php|inc|theme)$})
end
end
All this does is tells Compass where my config.rb is... Which is in the base of my site where my Guardfile is kept. Then it has compass compile the SCSS.
Not sure about your situation but in mine I needed to set the host and port for it to work smoothly. But basically guard will watch for a change and once compass outputs the css file LiveReload notices the change and then reloads that file. Pretty simple.
Im sure you know already but add all the correct Gems to your Gemfile, run 'bundle' on your project and then initiate Guard using $ guard
In your browser make sure you hit the LiveReload button and it will tell you in the terminal that browser is connected and away you go.
Hope that helps.
I'm getting the above error in a gem with this code snippet
Savon.configure do |config|
config.log = false
config.log_level = :error
HTTPI.log = false
end
This code used to pass in past runs on Travis, so I'm not sure why this changed when I altered the Readme.
Part of this confusion comes from my situation--inheriting a gem to maintain--along with this line in the gemspec:
gem.add_dependency 'savon'
There's no version number specified, so the newest run switched over to using Savon 2, which ditched the Savon.configure global behavior. If you're in the same boat as me, changing this line to the last pre-2.0 version of Savon will resolve the issue:
gem.add_dependency 'savon', '~>1.2.0'
Then bundle install and you should be good.
Or you want to upgrade your code. I know I do.
Savon.configure was removed from Savon 2.0 because the "problem was global state". The quickest way to keep the behavior the same in your app would be to define a app-level global hash in the same place. You'd then pass this hash into every Savon.client call you make. For instance:
# Where Savon.configure was called
APP_OPTS = {
# disable request logging, silences HTTPI as well
log: false,
# Don't log Laundry xmls to STDOUT
log_level: :error,
#... etc
}
# Elsewhere
#client = Savon::Client.new(APP_OPTS)
I'd consider this a starting point to migrating to the 2.0 configuration style. Ideally, you should always consider the client-specific 2.0 options available when initializing each Savon client.
So here's what I'm attempting to do. I'm building an ember.js application, with a java backend running on GAE.
I'm using handlebars, but I want them divided up into separate files, not just all pasted into the index.html.
Via the ember.js irc I was turned on to rake-pipeline along with minispade
Along with the web filters and a custom handlebars filter I started building the assetfile. I don't know Ruby, or gem files, etc.
So I'm trying to figure out the best way to be able to compile my coffeescript/handlebars files on the fly, minispade them, but keep the individual files accessible while in dev mode so I can debug them. What makes that hard is that the rake pipeline is running on a different port than GAE. So I'm not sure exactly how to handle this. Do I make my index file in GAE point to individual files at the 9292 port (rakep) during development, but in production mode point to the fully concatenated version? I'm not sure.
So I was attempting to do that here: https://gist.github.com/1495740 by having only one section that was triggered by the 'build' flag. Not even sure if that works that way.
I know there's a lot of confusion here. Apologies, like I said I'm not even remotely familiar with the Ruby style of doing things.
Since you're not a Ruby person, here are the most reliable steps for getting a stock OSX environment set up with rake pipeline:
Step 1: Install bundler
# on OSX, using built-in Ruby
$ sudo gem install bundler --pre
Step 2: Create a Gemfile
# inside your app directory
$ bundle init
# will create a file named Gemfile in the root
Step 3: Add rake-pipeline to the Gemfile
# inside the Gemfile
gem "rake-pipeline-web-filters"
Step 4: Install your gems
$ bundle install --binstubs
Step 5: Set up Assetfile
However you were already doing it...
Step 6: Run Rake::Pipeline
# to run the preview server
$ bin/rakep
# to build your assets
$ bin/rakep build
Rake::Pipeline.build is the method that evaluates an Assetfile. You can imagine that your entire Assetfile is wrapped inside a Rake::Pipeline.build {} block; you shouldn't ever need to write one inside an Assetfile.
Some of the filters in the docs are hypothetical, most of those docs were written before there were any filters at all. A CoffeeScript compiler has been recently added, though.
As to your main question, I'm not sure there's a clean way to do it with the current rakep implementation. An Assetfile is just Ruby, though, so it's possible to hack something together that should work. Here's how I would write yours:
require "json"
require "rake-pipeline-web-filters"
require "rake-pipeline-web-filters/helpers"
class HandlebarsFilter < Rake::Pipeline::Filter
def initialize(&block)
block ||= proc { |input| input.sub(/\.handlebars$/, '.js') }
super(&block)
end
def generate_output(inputs, output)
inputs.each do |input|
output.write "return Ember.Handlebars.compile(#{input.read.to_json})"
end
end
end
# process all js, css and html files in app/assets
input "assets"
# processed files should be outputted to public
output "public"
# process all coffee files
match "**/*.coffee" do
# compile all CoffeeScript files. the output file
# for the compilation should be the input name
# with the .coffee extension replaced with .js
coffee_script
# The coffee_script helper is exactly equivalent to:
# filter Rake::Pipeline::Web::Filters::CoffeeScriptCompiler
end
match "**/*.js" do
minispade
if ENV['RAKEP_ENV'] == "production"
concat "application.js"
else
concat
end
end
match "**/*.handlebars" do
filter HandlebarsFilter
minispade
concat "templates.js"
end
The if ENV['RAKEP_ENV'] bit reads an environment variable to decide whether to concatenate your JS to a single file.
So now you can run RAKEP_ENV="production" rakep build for a concatenated build, or just rakep build for a development build.
I'm trying to replace fixture generation with factories using rails3-generators:
https://github.com/indirect/rails3-generators#readme
The gem is included in my Gemfile and has been installed:
# Gemfile
gem 'rails3-generators', :group => :development
I added the following to application.rb:
# application.rb
config.generators do |g|
g.stylesheets false
g.fixture_replacement :factory_girl
end
Yet 'rails g model Insect' is still generating fixtures ('insects.yml'). Is this working for others using Rails 3.0.4 and rails3-generators 0.17.4?
'rails g' shows the new generators available (such as Authlogic and Koala), but 'rails g model' still lists fixtures and doesn't refer to factories.
What else should I add to get this to work? Thanks.
Edit: I ran the gem's test suite, which includes a test for this, and it passes. No clue why it doesn't work with my app.
Edit2: I tried again with a test project and get the same result: fixtures instead of factories. If anybody could confirm whether this works for them with Rails 3.0.4 and rails3-generators 0.17.4, that would be helpful too because it would imply that I'm doing something wrong with my projects.
Edit3: It works if I run 'rails g model Insect -r factory_girl'. I thought the generator configuration in application.rb was supposed to take care of that, so this seems to be the source of the problem.
Searching around I found the following, which may help:
Try specifying a directory option for factory_girl's factories:
config.generators do |g|
g.stylesheets false
g.fixture_replacement :factory_girl, :dir => "spec/factories" # or test/factories, as the case may be
end
If you're using Test::Unit, try the following:
config.generators do |g|
g.stylesheets false
g.test_framework :test_unit, :fixture_replacement => :factory_girl
end
In both cases you will still need the rails3-generators gem, although there is a push to get that functionality into factory_girl_rails.
This Rails bug indicates that, at some point, the g.fixture_replacement code may not have worked right. Perhaps a test in 3.0.5 is in order. :)
A short update 9 years later:
instead of "factory_girl_rails" (which is deprecated now) use "factory_bot_rails".
Now, the factory gets created automagically:
$ rails g model tester name:string
Running via Spring preloader in process 31467
invoke active_record
create db/migrate/20200327152901_create_testers.rb
create app/models/tester.rb
invoke rspec
create spec/models/tester_spec.rb
invoke factory_bot
create spec/factories/testers.rb
I use rails 5.2.4, but this should also work with rails 6.