Using Sprockets as a Standalone Service for a PHP Application

Middleman sprockets fingerprint

I haven't found a out of the box solution for this, but I made my own solution. In the config.rb I'm running the after_build hook. Not the best way, but it works:

after_build do
require 'fileutils'
delete_except "build/javascripts/", "all.js"
delete_except "build/stylesheets/", "all.css"

require 'digest/sha1'
sha1 = Digest::SHA1.hexdigest Time.now.getutc.to_i.to_s
allJS = "all-" + sha1 + ".js"
allCSS = "all-" + sha1 + ".css"
File.rename("build/javascripts/all.js", "build/javascripts/" + allJS)
File.rename("build/stylesheets/all.css", "build/stylesheets/" + allCSS)

index_file = "build/index.html"
html = File.read(index_file)
html = html.gsub(/all\.js/, allJS)
html = html.gsub(/all\.css/, allCSS)

File.open(index_file, "w") { |file| file.puts html }
end

I'm doing the following:

  • delete unnecessary generated .js and .css files
  • generating a sha1 hash based on time (that's enough for me)
  • appending the hash to the files
  • updating the index.html with the new file names

rails uninitialized constant Sprockets::SassCacheStore

Okay so here goes:

I've found the problem and it was solved by actually supplying a version that works with rails 4.2.

The default gem compass-rails installs a version incompatible with sprockets.

When I added the specific version as seen here and ran another bundle the versions of most of the packages I named in the question changed.

console output after gemfile modification included:

Installing sprockets 2.12.3 (was 3.0.0)
Using sprockets-rails 2.3.1 (was 2.2.4)
Installing sass-rails 5.0.1 (was 5.0.3)
Installing compass-rails 2.0.4 (was 2.0.1)

Guess it's just waiting for compass to release a compatible version.

Converting server operation system Windows XP to Ubuntu

I'm not genes in zend framework. But I use zend project in both Windows and Linux environment.

File formatting is not problem in both OS. Because php, phtml, ini etc.. file are working in both system.

In linux you should give read permission to web user for your project.

Rails - Bootstrap setup

You are in configuration hell, and I have built a minimal working product to get you out of there. In order to achieve this, we tackle your problems in order of their appearance and do not try to solve them in parallel. This answer focuses on your first question and probably solves the others.

The copy of the project's Readme follows. In case you need access to the product, just let me know.

README

This is a demo application to help stackoverflowuser "user2860931" with issues
as mentioned here.

Questions are listed in chronological order:

[Q1] November, 13
Rails with Bootstrap Tabs

[Q2] November, 22
Rails 4 - Bootstrap date picker

[Q3] November, 24
Rails - Bootstrap setup

Problem Description

Many configuration attempts have been made and a suboptimal development
environment probably interrupted rails naming conventions by adding file
extensions.

Versions Used

Rails 4.2.5

Steps To Create This Application By Yourself

First check for an appropriate rails version

$ rails --version
  1. Make sure the development environment (IDE) does not add file extensions by itself

  2. Creating a new rails application


    $ rails new rescue

  3. Locate the Gemfile of the application created under 1. and comment out
    the turbolinks gem entry
    Remove explanatory links for visual clarity

  4. Add the following lines to you Gemfile (one might want to fix gems to a
    particular version in order to avoid an application to stop working by an
    unplanned update, but this is another issue)


    gem 'bootstrap-sass' #, '3.3.5.1'

  5. Run


    $ bundle exec bundle update
    $ bundle exec bundle install

  6. Create the file app/assets/stylesheets/custom.css.scss and add the following
    lines:


    @import "bootstrap-sprockets";
    @import "bootstrap";

  7. Add the following line to app/assets/javascripts/application.js


    //= require bootstrap

    IMPORTANT: This line has to follow the lines of jquery and jquery-ujs and
    before the require_tree directive so that the resulting file looks like:


    //= require jquery
    //= require jquery_ujs
    //= require bootstrap
    //= require_tree .

    NOTE: We have deleted the line for turbolinks, to reflect the production
    system's setup of user "user2860931" (stackoverflow).

  8. After saving all edited files, check whether the development environment
    has altered the file extensions (just to be sure this time)


    .
    ├── app
    │   ├── assets
    │   │   ├── images
    │   │   ├── javascripts
    │   │   │   └──application.js  

    │   │   └── stylesheets
    │   │   ├── application.css
    │   │   └── custom.css.scss

  9. Generate a minimal controller together with action and related view


    $ rails generate controller planets index

  10. Start the server


    $ rails s

  11. Visit in your browser


    http://localhost:3000/planets/index

  12. Last step to remove turbolinks completely

    1. View the HTML sourcecode of the site mentioned under 11.

    2. From file app/views/layouts/application.html.erb remove all
      data-turbolinks-track attributes so that the ERB code looks like:


      <%= stylesheet_link_tag 'application', media: 'all' %>
      <%= javascript_include_tag 'application' %>

    3. Repeat step 1. and note the difference

  13. Visit the file app/views/planets/index.html.erb and replace with your HTML
    as listed in [Q1]

  14. This setup renders your partials under the correct tabpanel. Be advised that
    that you are working in the development environment of Rails. A call to


    $ rake assets:clean
    $ rake assets:precompile

    could be needed in order to see changes once you deploy your main project (it should not be needed in Rails development mode).

    Tip: Use mock data files as arguments for the render function.


    app
    │   └── views 

    │   │ 
    │   └── planets
    │   ├── _dummy00.html.erb
    │   ├── _dummy01.html.erb
    │   ├── _dummy02.html.erb
    │   ├── _dummy03.html.erb
    │   ├── _dummy04.html.erb
    │   ├── _dummy05.html.erb

and use calls to render 'planets/dummy05' in your HTML of Q1. Make sure each dummy file contains slightly different data, in order to be able to check for working tabs.

The mock-up result provides tabs via bootstrap and looks like this this.

Tabs are working as expectedexpected.

By providing you with the minimal working product, you should be enabled to bring your setup to a working state.

After all the preparation, adding a datepicker by just following the official documentation works, which answers Q2:

datepicker-picture

Sources Used To Provide This Answer

https://www.railstutorial.org/ by Michael Hartl

http://getbootstrap.com/components/#nav

http://getbootstrap.com/javascript/#tabs

http://getbootstrap.com/javascript/#tabs-usage

http://guides.rubyonrails.org/asset_pipeline.html



Related Topics



Leave a reply



Submit