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

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

Related

Setting expanded output style in sass doesn´t work

I want to change output style in my sass file to expanded but setting :
sass --watch style.scss:style.css --style expanded
doesn´t work for me. Instead it return me this
Encoding::CompatibilityError: incompatible character encodings: CP852 and UTF-8
Use --trace for backtrace.
Is there any possible to fix it? I´m not quite sure about it too because I´m new in Sass.But when I tried first , things went well in my single line selector in compresed style .I did some changes in sass file, I have here now more selectors formated in expanded output style , but it seems that problem is that compiler still want to see my sass file in compresed output style because it gives me back this:
Compilation Error
Error: Invalid CSS after "body {": expected "}", was "{"
on line 1 of sass/c:\Users\Doma\Desktop\Nové webovky\Javascript
& webovky\alfabeta\pionyr.sass
body { {
Can someone please help? Maybe is some basic thing but I really didn´t find solution to this and I searched in many sources
Thank you very much
that happening because you use native language not english for your operation system to change that and make sure sass compiler working without errors write this in terminal/command line before you use sass compiling command chcp 1252 after code activated use sass compile as expected sass --watch style.scss:style.css --style expanded
update
sometimes this error happening because silly mistake try this may help some causes this solution with helpfully change the path name from c:\Users\Doma\Desktop\Nové webovky\Javascript & webovky\alfabeta\pionyr.sass to c:\Users\Doma\Desktop\Nov webovky\Javascript & webovky\alfabeta\pionyr.sass
just take out é form the folder path and try again.

IntelliJ Ruby warning "Cannot resolve properly, was not processed"

I have many lines in my specs that result in this IntelliJ warning:
"Cannot resolve properly, was not processed"
The vast majority of the lines have this format:
expect(result[:err]).to include('(Check the file permissions.)')
If I move the literal string to a separate variable, the warning goes away:
msg = '(Check the file permissions.)'
expect(result[:err]).to include(msg)
Is there a way to make this error go away (other than moving all my string literals to variables)?
My guess is that the RubyMine parser thinks that include is the Ruby keyword to include a module and so it emits a warning telling it cannot find the corresponding module.
The only way I found to fix this warning is to use the inclusion alias proposed by the rspec include matcher :
expect(result[:err]).to inclusion('(Check the file permissions.)')
This fixes the warning and the expectation works the same, but sadly the english sentence is bad.
There is also 3 other aliases available, but they don't give better english syntax:
alias_matcher :a_collection_including, :include
alias_matcher :a_string_including, :include
alias_matcher :a_hash_including, :include
alias_matcher :including, :include
These alias definitions can be found here
Maybe by chance this answer could lead someone to a better solution.
If you're willing to switch from using the word include to something like contain, you could simply create a custom matcher:
RSpec::Matchers.define :contain do |expected|
match do |actual|
expect(actual).to include(expected)
end
end
You could either add that code directly in your rails_helper.rb file, or better yet in a separate file. For instance, create spec/support/custom_matchers.rb and place the code there. You'll need to make sure that file gets included when running rspec. To do that, you could uncomment the following line which appears in the default spec/rails_helper.rb file:
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
With that in place, your spec file would read:
expect(result[:err]).to contain('(Check the file permissions.)')
It can be fixed by adding this to rails_helper.rb or support/rubymine_stubs.rb:
# Rubymine IDE underlines `include` matchers with warning "Cannot resolve properly, was not processed"
# To fix this issue let's make an alias `contain` and use it instead
RSpec::Matchers.alias_matcher :contain, :include
module RubymineStubs
# create stub for `contain` so Rubymine won't underline it
def contain(*_args) end
end

Can't generate ruby exe using ocra due to ARGV[0]

Running the command ocra script.rb --no-autoload --no-enc --add-all-core gives me the error initialize: can't convert nil into String (TypeError) for the following line:
doc = Nokogiri::XML(File.open(ARGV[0]))
Whats going on here? I want to build the executable to be able to take any argument and use that file as the xml configuration.
It seems a long time but the accept solution doesn't work for me.
The working solution is adding -- then any fake data to your argument to make the execution flow to be just as normal
example for:
so you need to do
ocra yourscript.rb -- ANYDATAHERE
Just add this above that line:
exit if defined? Ocra
# skip anything below this line when we're building the exe
Unless there's a require or otherwise loaded dependency below that line you should be fine.

Ruby require_relative not loading file, not throwing error

I am having trouble getting constant definitions loaded via an external file. I have narrowed the problem down to the following.
require_relative '../../common/config.rb'
A_CONSTANT = 'something'
puts "A_CONSTANT: #{A_CONSTANT}"
When I run this as written, it prints the message correctly. The same constant is declared in the file common/config.rb. The relative path is correct for the location of this file. Just for completeness, the above code is in /watir/dashboard/spec/ex.rb. The constant is declared in /watir/common/config.rb.
As I see it, the above code should error out for a duplicate constant declaration. It does not. If I comment out the constant declaration above and rerun, the puts statement shows an error for 'uninitialized constant.' Any ideas what's wrong?
Edit - The contents of the file common/config.rb are below.
A_CONSTANT = 'something'
On a lark, I changed the filename to common/conf.rb. When I modify the require_relative statement to load the renamed file, I get the results I originally expected. The file is loaded and the second constant declaration throws a warning saying 'already initialized constant.' If I comment out the second declaration, the script runs perfectly.
It appears that the filename 'config.rb' is somehow special when loaded by a relative path. I have use that filename in other scripts where it was in the same folder as the loading script or a sub-folder. This is the first time I have had to move up the tree to load it.
Ruby allows redefining constants, and will only print a warning. Some setting in your Ruby is just hiding that warning from you.

Cucumber - Custom HTML Formatter Basics

I'm looking to do something relatively simple with a custom cucumber html formatter which is to display the reports where the scenarios are collapsed by default instead of expanded. I have been using this reference as a starting point for implementation:
https://github.com/cucumber/cucumber/issues/113#issuecomment-1997654
I have done the following:
Copied the html.rb file to my features/support and renamed it my_html.rb
Modified the before_steps method to use #builder << ''
Altered the class definition within the file from Html to MyHtml
Attempted to call the formatter using 'cucumber -d -f Cucumber::Formatter:MyHtml'
but I get
no such file to load -- cucumber:formatter:my_html
Error creating formatter: Cucumber:Formatter:MyHtml (LoadError)
so I try and specify the file itself but get the same error.
I'm relatively new to cucumber and object orientation so my simple question is - how do I get this to work?
I believe my environment is Ok I have an env.rb and hooks.rb file in the same features/support directory that are picked up ok.
Also, once I get it to see where the file is, do I need to modify the require statements as those (relative) references don't exist under my features/support directory..
Thanks in advance
You seem to missing a colon, i.e. instead of
cucumber -d -f Cucumber::Formatter:MyHtml
try
cucumber -d -f Cucumber::Formatter::MyHtml
A simple hack to collapse the HTML report uses following command after the report is generated.
sed -e "s/<\/script><\/div><\/body><\/html>/\$(function(){\$('.keyword').click();});<\/script><\/div><\/body><\/html>/g" report.html > report2.html
This is worked for me.

Resources