Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:31:45+00:00 2026-06-15T01:31:45+00:00

I don’t have much experience with Ruby. I want to @import sass from database

  • 0

I don’t have much experience with Ruby. I want to @import sass from database instead of filesystem. I did not find any examples online. How should I go about implementing this. I see that I have to extend an importer class but since I have no understanding of ruby I need to know where in my filesystem does this class reside (Just to check it out) and in general what are the basic steps involved.

More information

MySQL database contains sass content.
So in my web application I accept sass (as string) from user which may contain an import statement for example :

@import test.scss
body  { color:red } 

Now in my MySQL DB I will have something like this

Table  sass_files
column_name             filename  |   content
example row             test.scss |   p {color:blue;}

I want to make this import work, sure I can just do a regular expression match to get the filename from the user input and then query the DB by that file name and get the content.
But I read that there is a nice way to make ruby/sass use DB as a load-path instead of filesystem.

UPDATE

SO i created a dummy custom importer class with find method as

def find(name, options)
  Sass::Engine.new("p { color :blue; }", options)
end

How do i add this importer to sass load paths w/o using ruby, like can i make change to the source files in the sass gem folder and add this importer to lib/sass/importers?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:31:46+00:00Added an answer on June 15, 2026 at 1:31 am

    Since you’re using Compass to compile, you can add a custom Sass importers in the Compass config file. For example, compiling using compass compile -c config.rb, you would include something like this in your config.rb file:

    require File.join(File.dirname(__FILE__), 'importer.rb')
    Sass.load_paths << Sass::Importers::Custom.new()
    

    Then in importer.rb in the same directory, you would include your importer definition:

    module Sass
        module Importers
            class Custom < Base
                def find(name, options)
                    if name == '[globals]'
                        options[:syntax] = :scss
                        options[:filename] = 'globals'
                        options[:importer] = self
                        return Sass::Engine.new("$imported-variable: blue;", options)
                    else
                        return nil
                    end
                end
    
                def find_relative(uri, base, options)
                    nil
                end
    
                def key(uri, options)
                    [self.class.name + ":" + uri, uri]
                end
    
                def mtime(uri, options)
                    nil
                end
    
                def to_s
                    '[custom]'
                end
            end
        end
    end
    

    Then in your Sass file you can use the importer:

    @import '[globals]';
    p {
        color: $imported-variable;
    }
    

    Of course, this is just a dummy implementation that only accepts a URI matching "[globals]". You’ll need to supply your own implementation that accesses your MySQL database, as I don’t have any experience with database access in Ruby. Hopefully this should get you a little closer, though, in addition to the links that @Sean has provided.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't want my user to even try downloading something unless they have Wi-Fi
Don't have much to say, just can get into the event handler. XAML: <Grid>
I don't have much knowledge about the IPv6 protocol, so sorry if the question
Don't want to sort the entries. using this does not preserve the order as
Don't ask me how but I'm in a situation where I have DCPs published
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face
Don't ask why but I have the requirement to draw a border around certain
Don't know why people do not practice AJAX implementation for authentication systems. Is it
Don't they both have to convert to machine code at some point to execute

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.