coffeescriptsassrhomobilerhodes

How to write coffee-script and sass in Rhodes / RhoMobile?


I would like to write sass and coffee-script code in Rhodes/RhoMobile and let the compiler automatically compile to js and css file before run or build task, for every platforms I am targeting


Solution

  • In this example you place your sass files in assets/stylesheets directory. Processed and compressed files will output in public/css. This also preserve the sub directory structure

    An error during compilation will stop the process

    Adjust the before hook depending on the platform your are targetting

    Add this task at then very end of your Rakefile:

    task :precompile_css do
      Dir.chdir $app_path do
        exit_code = system 'scss --force --update assets/stylesheets:public/css --style compressed'
        raise 'Precompile error' unless exit_code
      end
    end
    
    # Add all platforms you need.
    # To get the exact name of the task to hook you can execute 
    # $ rake -n run:my_platform
    task 'config:android' => :precompile_css
    task 'config:wm' => :precompile_css
    etc ...
    

    Also possible with coffeescript

    task :precompile_js do
      Dir.chdir $app_path do
        exit_code = system 'coffee --compile --output public/js/ assets/javascripts/'
        raise 'Precompile error' unless exit_code
      end
    end
    
    task 'config:android' => :precompile_js
    task 'config:wm' => :precompile_js
    etc...
    

    Then just invoke your run or build tasks as usual