Compass from Ruby—SassCompiler not found - ruby

I have a little ruby script that uses Compass to compile *.scss files, since Compass and Sass are ruby-based I am just using the compiler directly like this (based on this SO question):
require 'compass'
require 'sass'
Compass.add_configuration({
:project_path => '.',
:sass_path => 'css',
:css_path => 'css',
:output_style => :compressed
},'custom')
Compass.compiler.compile('css/index.scss', 'css/index.css')
That works as expected and does the compilation, BUT, I also get this message:
Compass.compiler is deprecated. Use Compass.sass_compiler instead.
So I tried to use:
Compass.sass_compiler.compile('css/index.scss', 'test.css')
What throws an Error, telling that the class SassCompiler (NoMethodError) is not defined.
I really would like to use the suggested method, but can I use it and what do I have to require in ahead?
Thanks for help!

After digging a bit into the source, I finally found it!
require 'compass/sass_compiler'
is the missing line!
The final line to run the compilation looks like that:
Compass.sass_compiler.compile!
Thats it.
Btw.: the Compass.sass_compiler method accepts some options (source) which are handed over to the compiler, but using Compass.add_configuration as above does the same Job.
I hope somebody can use this Information, happy compiling!
EDIT
Due to the comments here the complete code that works for my project. It is included in a build script, the following lines are from the initialisation:
require 'compass'
require 'compass/sass_compiler'
Compass.add_configuration({
:project_path => _(),
:output_style => :expanded,
:cache_path => '<path to cache>',
:http_fonts_path => '../fonts',
:fonts_dir => '<relative path to fonts>',
:sass_path => '<path to the scss files>',
:css_path => '<path fot the compiled css>',
:http_images_path => '../img',
:images_path => '<path to images>'
},'custom-name')
And these line run in each compilation:
compiler = Compass.sass_compiler({
:only_sass_files => [
'<path to scss file to compile>'
]})
compiler.compile!
To get an overview of all possible options I recommend a look at the source and at the official documentation of sass and compass.

Related

How to get started using aws_account_utils (ruby)?

After searching around, I found this aws_account_utils which does exactly what I hope to achieve - programmatically create aws account.
Unfortunately as a total ruby noob, I have no idea how to start using it even after reading the README.md.
I suspect I'd need the following steps:
Create create-account.rb
Use the util in the code
Run ruby create-account.rb
How should the content of create-account.rb be like?
Please show me a template.
With that I should be able to start experimenting and hacking.
Any other steps I should do?
Thanks in advance.
Plan below is rough and must be supplemented.
Create Gemfile file. This file is needed to specify project dependencies (libraries)
Put this line into Gemfile
gem 'aws_account_utils'
Run bundle install in your console / terminal
Create create-account.rb file with next code
require 'aws_account_utils'
aws_utils = AwsAccountUtils::AwsAccountUtils.new()
details = { 'fullName' => 'Herman Munster',
'company' => 'The Munsters',
'addressLine1' => '1313 Mockingbird Lane',
'city' => 'Mockingbird Heights',
'state' => 'CA',
'postalCode' => '92000',
'phoneNumber' => '(800) 555-1212',
'guess' => 'Test Account' }
resp = aws_utils.create_account(account_name: 'My Test Account 01',
account_email: 'adfefef#gmail.com',
account_password: 'foobar1212121',
account_details: details)
This code uses aws_account_utils library. Documentation you can find here.
After steps above you can run ruby create-account.rb.

How to use SASS/ SCSS in Yii2?

I want to use sass/scss in a new project, but it somehow doesn't work.
I am using the yii2-asset-converter and when I try to convert the scss-file, the following error is thrown:
Class #app/extensions/assetparser/vendors/phamlp/sass/SassParser does not exist
I am checking the path ../phamlp/ and notice, that the Folder sass resp. SassParser.php doesn't exist.
The SassParser.php is located in the extension vendor/richthegeek/phpsass, which is required by yii2-asset-converter.
I have tried out some paths like:
# vendor/richthegeek/phpsass or
__DIR__/../../vendor/richthegeek/phpsass
But it doesn't worked .After a lot of unsuccessful attempts I hope some of you know how to solve the problem.
PS:I use the advanced app template
Don't use PhalmP or phpsass. These are outdated. You'll never get satisfactory results with them, especially when using modern Sass libraries.
Use original Sass as a standalone.
Simply install Ruby (you might already have it) and Sass and use the sass command line tool to compile.
Also, using Compass might make your life easier. Compass helps organizing your Sass code and also provides a Sass library with a lot of useful helpers.
You can use this plugin.
But you must combine your sass code in single file.
Here's example of config/web.php
'assetManager'=>[
'converter'=>[
'class'=> 'nizsheanez\assetConverter\Converter',
'force'=> true, // true : If you want convert your sass each time without time dependency
'destinationDir' => '', //at which folder of #webroot put compiled files
'parsers' => [
'scss' => [ // file extension to parse
'class' => 'nizsheanez\assetConverter\Scss',
'output' => 'css', // parsed output file type
'options' => [ // optional options
'enableCompass' => true, // default is true
'importPaths' => ['/sass','/sass/_offers'], // import paths, you may use path alias here,
// e.g., `['#path/to/dir', '#path/to/dir1', ...]`
'lineComments' => true, // if true — compiler will place line numbers in your compiled output
'outputStyle' => 'expanded', // May be `compressed`, `crunched`, `expanded` or `nested`,
// see more at http://sass-lang.com/documentation/file.SASS_REFERENCE.html#output_style
],
],
]
]
]

Using guard live reload and guard compass seems to conflict

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.

Service to compile SASS online: is it safe to allow users manually import Compass extensions?

I'm creating another HTML/CSS fiddle web app. It is based on Sinatra and supports SASS with Compass extensions.
Here's how it works.
1) Require Compass and extensions:
require 'compass'
require 'singularitygs'
require 'breakpoint-slicer'
2) Add Compass load paths into Sass class:
Compass.sass_engine_options[:load_paths].each do |path|
Sass.load_paths << path
end
This code is borrowed from SassMeister.
3) Receive an AJAX request with SASS, compile and return CSS:
post '/compile-sass' do
sass = params[:sass]
begin
sass(sass.chomp, {:style => :nested, :quiet => true})
rescue Sass::SyntaxError => e
status 200
e.to_s
end if sass
end
Kinda very simple functionality. A user has to provide SASS code where manually he #imports any of supported Compass extensions:
#import breakpoint-slicer
html
+from(3)
background-color: pink
Questions:
Is it safe to let users import anything? When an extension outside of SASS load paths is being imported, SASS won't compile and throws an error. But JedFoster, the author of SassMeister, considers such behavior a performance and security hole and has made SassMeister comment out manual imports. Why?
Is there anything that i can improve in the given code?

Less not compiling automatically with pow

I'm building an application with Padrino, and I've decided to use less for the stylesheet, mostly to use twitter bootstrap.
I am having some trouble getting less to automatically compile my less files when serving the app via pow.
When I run padrino start and use the embedded server, I get nice styling, but I don't really understand how. The application.css file that is generated is exactly how it should be, except there are no changes to the application.css file in my app's public dir.
When I run the app through pow, though, no changes made to the application.less file are reflected on the application.css file, which is the only one served.
I'm mostly trying to understand how and why less is only compiled when running webrick.
My less initializer is:
module LessInitializer
def self.registered(app)
# Enables support for Less template reloading for rack.
# Store Less files by default within 'app/stylesheets/'
# See http://github.com/kelredd/rack-less for more details.
require 'rack/less'
# optional - use as necessary
Rack::Less.configure do |config|
config.compress = true
config.cache = true
# other configs ...
end
app.use Rack::Less,
:root => Padrino.root,
:source => 'app/stylesheets',
:public => 'public',
:hosted_at => 'stylesheets'
end
end
And my application.less file is:
#import "bootstrap/bootstrap.less";
body {
padding-top: 60px;
padding-bottom: 40px;
}
.sidebar-nav {
padding: 9px 0;
}
I've just tried this with Padrino edge and Pow and it's working alright.
To be honest, it shouldn't really make a difference whether it's Pow or Webrick - as long as it's rack complaint it should just work.
You can try changing padrino's gem on your test project to point to:
gem 'padrino', :git => 'git://github.com/padrino/padrino-framework.git'
There's currently an unmet dependency for less on edge but it should be merged soon. So if the above didn't work, use this:
gem 'padrino', :git => 'git://github.com/padrino/padrino-framework.git', :branch => 'fix-less-dependencies'
If you keep on having a problem, would you mind opening an issue on Github?
Thanks!

Resources