Can I use regular expressions with guard-concat? - ruby

I'm using the guard-concat plugin for guard to concatenate my handlebar template files.
Can I use regular expression to make it concat all files in one folder instead of typing in all the names of the files?
so instead of doing this:
guard :concat, type: "php", files: %w(a b b/c b/d), input_dir: "app/views/handlebars", output: "app/views/handlebars/all"
I could do this:
guard :concat, type: "php", files: %r{.+}, input_dir: "app/views/handlebars", output: "app/views/handlebars/all"
When I do that I get the following error:
ERROR - Invalid Guardfile, original error is: > [#] undefined method `join' for /.+/:Regexp

Francesco Canessa (responsible for guard-concat) has told me
I can implement this feature but usually the files order is important
both for CSS and JS (for example for code that needs libraries to be
loaded first)
So this is not possible today but might be added in future releases.
link to the issue on guard-concat github page

You can use Dir#glob (or it alias Dir#[]):
Dir['*/**.php']
as argument. It will return array containing all files with .php extension in all subfolders.

Related

How check is my file create/modyfy after other file?

I need a function similar 'make' program.
If my file not exist or if file need update (modyfy time is before my other file) tell me true.
I have one file dependencies to other file. How update it only if neccesary.
You might want to use FileUtils.uptodate?.
uptodate?(new, old_list)`
Returns true if new is newer than all old_list. Non-existent files are older than any file.
In your example you can use it like this:
unless FileUtils.uptodate?('file_a', ['file_b'])
# file_a needs to be updated
end
require 'time_difference'
TimeDifference.between(File.ctime("FilenameA"), File.ctime("FilenameB.txt")).humanize
Using gem 'time_difference'
trouble with other lang than english (withouth .humanize You get number)

Fetch variable from yaml in puppet manifest

I'm doing one project for puppet, however currently stuck in one logic.
Thus, want to know can we fetch variable from .yaml, .json or plain text file in puppet manifest file.
For example,
My puppet manifest want to create user but the variable exist in the .yaml or any configuration file, hence need to fetch the varibale from the outside file. The puppet manifest also can do looping if it exist multiple users in .yaml file.
I read about hiera but let say we are not using hiera is there any possible way.
There are a number of ways you can do this using a combination of built-in and stdlib functions, at least for YAML and JSON.
Using the built-in file function and the parseyaml or parsejson stdlib functions:
Create a file at mymodule/files/myfile.yaml:
▶ cat files/myfile.yaml
---
foo: bar
Then in your manifests read it into a string and parse it:
$myhash = parseyaml(file('mymodule/myfile.yaml'))
notice($myhash)
That will output:
Notice: Scope(Class[mymodule]): {foo => bar}
Or, using the loadyaml or loadjson stdlib functions:
$myhash = loadyaml('/etc/puppet/data/myfile.yaml')
notice($myhash)
The problem with that approach is that you need to know the path to file on the Puppet master. Or, you could use a Puppet 6 deferred function and read the data from a file on the agent node.
(Whether or not you should do this is another matter entirely - hint: answer is you almost certainly should be using Hiera - but that isn't the question you asked.)

Loading Ruby scripts in SketchUp: LoadError: (eval):0:in `load': no such file to load

I have been trying to manually load Ruby scripts into SketchUp manually, using load. I always get an error back saying the file is non existent even though it is there in the directory.
Here is a sample of my code:
load "H:Document\sclf_color_by_z_1.6.1_1.rbz"
and the error messages:
Error: LoadError: (eval):0:in `load': no such file to load -- H:Document clf_color_by_z_1.6.1_1.rbz>
(eval)
(eval):0
Three issues here:
H:Document\sclf_color_by_z_1.6.1_1.rbz is not a valid path. After the Drive specifier H: you you should have a separator: \ - like so: H:\Document\sclf_color_by_z_1.6.1_1.rbz
Beware escape characters in strings when you program. \ is such a character.
To correct your string you'd have to have something like this:
"H:\\Document\\sclf_color_by_z_1.6.1_1.rbz"
https://en.wikibooks.org/wiki/Ruby_Programming/Strings#Escape_sequences
However, note that the convention for Ruby is to use forward slashes - even on Windows: "H:/Document/clf_color_by_z_1.6.1_1.rbz"
You are trying to load an RBZ file here. This is not the same as an RB file. An RBZ is a packaged SketchUp extension (actually a ZIP file). To programmatically install an RBZ you must use Sketchup.install_from_archive("H:/Document/clf_color_by_z_1.6.1_1.rbz")
http://www.sketchup.com/intl/en/developer/docs/ourdoc/sketchup#install_from_archive
Note that Sketchup.install_from_archive is nothing like load - it permanently installs the extension to SketchUp where as load would be just for that session.
Whenever you have a filepath that you think should be on disk - as the system whether it can find it: File.exist?("H:\Document\sclf_color_by_z_1.6.1_1.rbz") If that return false you know you need to carefully check your path again checking for syntax errors and typos.
You should use File.join() method. In your case:
You can't use load for a .rbz file but you can use Sketchup.install_from_archive() as thomthom said
So in your case your can simply do:
file = File.join( 'H:', 'Document' , 'sclf_color_by_z_1.6.1_1.rbz' )
Sketchup.install_from_archive file

Embeddable Common-Lisp asdf:defsystem returning invalid relative pathname

I'm trying to learn how to use Common-Lisp's asdf, and I have the following code:
(asdf:defsystem example
:serial t
:components ((:file "first")
(:file "second")))
However, I keep getting the error:
Condition of type: SIMPLE-ERROR
Invalid relative pathname #P"first.lisp" for component ("example" "first")
I'm launching the repl in the same directory as these two Lisp files, but I don't understand why there is an error. What am I missing? I'm using ECL on Windows
ASDF uses *load-pathname* or *load-truename* to resolve the full paths to the system's components. If you enter the (asdf:defsystem ...) form on the REPL, these variables are not set.
Write the defsystem form into a file, then load it like (load "example.asd").

programatically invoking Sass::Exec::SassConvert generates wrong syntax

Sass::Exec::SassConvert.new(["{path_to_scss_file}.scss", "{path_to_css_file_to_generate}.css"]).process_result
When I run following command from inside a ruby script, the generated file contains "sass"-syntax instead of valid css
When I try to add a set_opts command to specify "-F scss -T css", just to be sure the convertor knows what to do, it throws an error:
NoMethodError: undefined method `banner=' for ["-F scss -T css"]:Array
The goal is to compile scss files to css files from inside an ant build script.
Everything is working except for the wrong syntax issue.
Is there anything I'm missing here?
I rewrote the script to use Sass::Engine instead of SassConvert.
After looking through the code of the SassConvert class, the following fragment pointed me to the solution:
unless [:scss, :sass].include?(#options[:to])
raise "Unknown format for sass-convert --to: #{name}"
end
It appears the SassConvert class only converts CSS files to .scss or .sass, not the other way around.
Also, the correct way to add option flags when calling Sass::Exec::SassConvert, is by doing the following:
sassConvert = Sass::Exec::SassConvert.new(["-F scss", "-T sass", "{path_to_from_file}", "{path_to_file_to_generate}"]
sassConvert.parse!
sassConvert.process_result

Resources