Git Product home page Git Product logo

themes_for_rails's Introduction

Theme For Rails (3 and hopefully later)

Features list

  • Support for adding themes which includes stylesheets, javascripts, views and layouts.
  • add a theme-image-url sass helper method for asset pipeline based themes
  • update the generators and rake tasks to support asset pipeline based themes
  • (NEW) works with the Rails Assets Pipeline without interfering, and leveraging it.

Compatibility

This gem works with Rails from version 3.0 to at least 3.2.1 (current at the moment of writing this readme file).

Documentation

Ideas / Inspiration

  • Add ThemesForRails::Railtie for configuration, so we selectively set the plugin on or off. Also to be able to change several settings.
  • Add routes to allow access to the theme’s static resources (js and cs), unless cached on public folder by capistrano / rake.
  • Extend Action View path in order to make the views accessible. Same for the layouts.
  • More tests ford edge cases. Now I am only testing the happy paths.

Rails 2 Support

This gem only works with Rails 3 (duh). If you want the same exactly behavior, but for Rails 2.x, go here .

Running tests

gem install bundler
bundle install
rake

Authors and contributors

  • lucasefe
  • jedifreeman
  • jbarreneche
  • kule
  • matheusmoreira
  • rafaelss
  • maxjgon

Last but not least

If you are using this gem, please, take a minute to recommend me at Working With Rails.

Recommend Me

themes_for_rails's People

Contributors

dmathieu avatar jbarreneche avatar jedifreeman avatar jenkek avatar kule avatar lucasefe avatar maxjgon avatar mguterl avatar nicolasgarnil avatar rafaelss avatar rivsc avatar tanraya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

themes_for_rails's Issues

Still an issue: Conflict with Rails Footnotes

When Rails Footnotes is turned on, the footnotes are shown at the botton of the screen, but the theme specific static files (stylesheets, javascripts, images) are returned as blank files.

When Rails Footnotes off, the static assets started working.

foot-notes are unusable with the themes gem. Not sure if this issue goes here or in footnotes.

generator missing

After executing: "rails generate themes_for_rails:install" I get the message "Could not find generator themes_for_rails:install"

error running rake assets:precompile

I'm running Rails 3.2.1 and themes_for_rails 0.5.1.

Trying to deploy and keep getting errors with precompiling assets.

In trying to narrow down the problem, I'm trying to run rake asset:precompile manually on my local machine, setting RAILS_ENV to production, which gives me the same error as what I see in my capistrano deployment.

Here's the error I keep getting, using the --trace option along with the rake task:

https://gist.github.com/2982787

Any ideas what I'm doing wrong here?

Thanks.

Public folder and already existing views.

Rather than having to work entirely inside each theme's folder, we should use already existing views and assets inside the public folder as the "default" theme.

Rationale

Applications usually have a default theme and make other themes selectable by the user. If we adapted the themes_for_rails workflow to take that into account we would gain several advantages:

  • Easier installation on an existing application; the developer doesn't have to move views and assets into a dedicated theme folder.
  • Easier removal; if the developer needs to drop theme support for any reason, all his original views and assets will be left intact.
  • Improved structure of the code base.

Implementation

themes_for_rails will not add a view path if a theme isn't valid. The behavior for assets, however, is still undefined.

We could simply not route the request to a specific theme if the user has not set a theme or set it to something like "default".

# lib/generators/themes_for_rails/assets_controller.rb

def asset_path_for(asset_url, asset_prefix)
  path = unless not valid_theme? or theme_name == "default"
           theme_path_for params[:theme]
         else
           'public'
         end
  File.join path, asset_prefix, asset_url # asset_url == params[:asset]
end

Side note

Can't the install generator add themes_for_rails to the list of routes?

# lib/generators/themes_for_rails/install_generator.rb

def add_themes_for_rails_routes
  route "themes_for_rails"
end

seeding data from a specific theme

Hi guys, I guess somthing like that would be useful...

namespace :db do
namespace :seed do
desc "Seeds a theme Usage: rake db:seed:theme THEME=your_theme"
task :theme => :environment do |t, args|
load(File.join(Rails.root, 'themes', ENV["THEME"], 'db', 'seed.rb'))
end
end
end

gem 0.5.0.pre broken on ruby 1.8.7

gem version 0.5.0.pre installed on a ruby 1.8.7 system breaks the whole rubygem repository. Although the installation is successful, any other gem command fails (e.g gem -v) fails with:

Invalid .gemspec format in '/Library/Ruby/Gems/1.8/specifications/themes_for_rails-0.5.0.pre.gemspec'

due to

<ArgumentError: Illformed requirement ["#YAML::Syck::DefaultKey:0x10aee33c8 3.0.11"]>

Apparently the gem on rubygems.org contain this strange ["#YAML::Syck::DefaultKey:0x10aee33c8 3.0.11"] instead of a simple "="

.....
s.add_development_dependency(%q, [">= 0"])
s.add_development_dependency(%q, [">= 0"])
s.add_development_dependency(%q, [">= 0"])
s.add_development_dependency(%q, [">= 0"])
s.add_development_dependency(%q, ["#YAML::Syck::DefaultKey:0x10aee33c8 3.0.11"])
.....

Building the gem locally (gem build themes_for_rails.gemspec) and installing it locally (gem install themes_for_rails -l -v 0.5.0.pre) everything works just fine.

No, problem with ruby 1.9.3 systems, as well.

Theme Names with Characters

I've got a theme with a period in the name such as testing.site. Unfortunately when I use the link tag helper:

<%= theme_stylesheet_link_tag 'styles' %>

It throws the following error:

No route matches {:controller=>"themes_for_rails/assets", :theme=>"testing.site", :asset=>"styles.css", :action=>"stylesheets"}

Any ideas?

theme_stylesheet_path for files with extension differs from standard rails

Where Rails' stylesheet_path will let you add your own extension, theme_stylesheet_path still tacks on the default extension, which is a problem for using it with for example LESS.js:

= stylesheet_path 'FOO.less'
= theme_stylesheet_path 'BAR.less'
/stylesheets/FOO.less
/themes/activate/stylesheets/BAR.less.css

Subfolders inside stylesheets folder

(Accidentally closed this issue, reopening)

Looks like themes_for_rails doesn't support subfolders within the stylesheets folder. I have a stylesheet which references an images folder inside the stylesheets folder. However, the stylesheet can't find the image file I'm trying to reference. When I visit the URL for the image like:

http://my.site.com/themes/my_theme/stylesheets/images/my_image.png

I get the following error:

not found

Mountable Engine

How to implement it on mountable engine? because i tested, it doesnt work. many thanks.

Sass compilation stopped working

The theme's stylesheet dir has the regular "sass" sub directory, yet the .sass file therein is not compiled to css. The sass gem is installed. What might be missing?

undefined method `theme' in controllers

When running v0.5.0 under:

ruby 1.9.3
rails 3.2.3

I realise Rails 3.2.2 might not be technically supported yet but thought I should mention it as reverting to v0.4.3 works ok for now.

undefined method `theme_image_path' for

Hi,
I am getting undefined method theme_image_path' for and undefined methodcurrent_theme_image_path' for
When I used them inside .css.erb files

What could be the problem here?

cache the *.css and *.js files

i found that when i use a customized theme, every time i refresh the page, all of the js and css files will be download, i thought this is a waste of resource, and can you do some fixes on your gem to add a cache function also make this gem more perfect??

javascript_path cannot get files with dotted names

problem using javascript path in Rails 3.1 (never got this problem before)

I know that current_theme_javascript_path('jquery.tools.min') returns the path to a file named query.tools.min.js

In fact, the output html seems to be fine

<script src="/themes/current_theme/javascripts/jquery.tools.min.js" type="text/javascript"></script>

but misteriously the browser returns this error
"NetworkError: 404 Not Found - http://localhost:3000/themes/current_theme/javascripts/jquery.tools.min.js"

btw, if I remove the dots from the filename renaming it, it works perfectly
current_theme_javascript_path('jquery_tools_min')

I tryed to watch to your code... sorry, I'm a front end developer! :)
Any ideas?

render does not find theme specific files

I am converting my project from Rails 2.3.x to Rails 3.0
I have replaced theme_support with this themes_for_rails gem.

In my views I have <%= render(:partial => 'some_partial' %> and with theme_support that was looking in the theme specific directory for this partial, but using themes_for_rails, that is not the case.

Jarl

Question about theme support at css(sass)

Hi!

-1.This is not problem, just question. I have not found more suitable place to put my questions.
-2.There are theme_image_tag & image_tag to overload an image at theme, but there are also css (sass) with code like this:
"
li
list-style: none
background: url(/images/decorators/square.png) left 2px no-repeat

"

Is any way to select rigth image at css/sass based on current theme? Are you planning to do something to resolve this problem? If yes, what exactly (I will try to help)?

Artem.

Rails 3.1

Any plans to support the new Rails 3.1 asset pipeline (/app/assets/..., scss, cofffeescript)?

theme_javascript_include_tag produces type="text/plain"

Somehow when using "theme_javascript_include_tag" in my project "<script type="text/plain" src="/themes/default/javascripts/jquery.jcarousel.min.js?locale=en"></script>" will be generated. I need the type attribute to be "text/javascript" otherwise some browsers may not interprete the JavaScript.

Is there a solution to this problem?

Greets,
Gambo

Avoiding duplicated static items

Hiya Lucas,

I'd really like to set this up so the images/javascripts/stylesheets directories could be symlinked to the actual themes directory e.g.

Rails.root/public/themes/theme_name ->
Rails.root/themes/theme_name/public/

Then in the theme folder you have:

$app_root
  themes/
    [theme_name]
      public/
         images/
         stylesheets/
         javascripts/
      views/
        layouts/

This way you don't need the themes:cache:create/update/delete tasks (but you'd need to setup the rails app/capistrano deploy task accordingly). It also means you can edit a theme design and have the changes reflect in your app straight away rather than having to run a rake task but still keeps the actual view files secure.

I'm thinking of creating this for myself but is this some you would be interested in having in the main gem?

[EDIT: opps; somehow this got submitted before I had finished]

Available themes + thumbs

Hey, my friend Ramon Soares give a idea about feature. This feature is a helper which return all themes on system and thumbs.

What do you think?
How do organization folder for thumbs?

"bundle exec rake assets:precompile" fails with themes_for_rails

Everything went well in the development environment. But when I run "cap deploy" (or "rake assets:precompile"), Rake aborted and gave the following log:

felixding@ubuntu:~/bbq$ bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
undefined method `controller_name' for nil:NilClass
  (in /bbq/themes/cover_wall/views/partials/_shelf_data.erb)
...

The "undefined method" error was caused by the following code:

controller.controller_name

It didn't have any problem until Rake. Any hints please?

bundle show an error with the gemspec file

bundle show themes_for_rails
Invalid gemspec in [/opt/bazarfactory/Bazar/vendor/ruby/1.8/specifications/themes_for_rails-0.5.0.gemspec]: Illformed requirement ["#YAML::Syck::DefaultKey:0x8ae0c10 3.0.11"]
Could not find themes_for_rails-0.5.0 in any of the sources

Controllers Override

Hi lucasefe,

    Using themes_for_rails we can override the views, stylesheets and javascripts.
    In the same manner, is it also possible to override the CONTROLLERS.
    If it is possible then please let me know how. It will be of great help to me and others.

    There are different solutions in INTERNET but I like the style of themes where there is a separate folder for each theme.

   Thanks a lot for this GEM.

Themes stored in Database

Dears,

i was looking for storing these themes in Database, as every user have and create his own theme. and to be also available of editing by users.

how that can be done with themes_for_rails

Best Regards,
Shenouda Bertel

Conflict with Rails Footnotes

This may be more of an FYI, but when Rails Footnotes is turned on, the theme specific static files (stylesheets, javascripts) are returned as blank files. When you turn Rails Footnotes off, the static assets start working.

SASS support

Sass in rails compiles templates in public/stylesheets. Some initializer to compile themes stylesheets in sass would be great.

Digests for precompiled assets

It looks like the helpers (ex: theme_stylesheet_link_tag) are not returning asset digest urls for assets, although the digest versions are available.

For example:

<%= theme_stylesheet_link_tag "application" =%>

returns the following (no digest):

<link href="/assets/themename/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />

Theme support for yml files

Hi!

-1.This is not problem, just question. I have not found more suitable place to put my questions.
-2.There are yml files for trunslation and I am using it like this:

  • <%= link_to t("sitemap.mapitems.primary.common.about_us"), {:controller => '/welcome', :action => "about_us"}%>
  • Are you planning to provide a overloading text for theme? If yes, what exactly (I will try to help)?

    Artem.

    Incompatible with Heroku

    Hello,

    I've not tested more than that to see the reasons. But this gem isn't compatible with heroku.
    The static files are just not displayed.

    URL helpers error - Asset Pipeline

    When trying to use the URL helpers:
    current_theme_image_path('logo.png', 'theme_name') # => /themes/theme_name/images/logo.png

    I get the following error:
    undefined method `base_theme_javascript_path' for #Frontend::ItemsController:0x007ffa85926aa8

    I'm using the Split Theme Storage method, and have included the relevant initializers. Do I need to include a 'default' theme for the url helpers to work?

    I'm not sure where base_theme... exists in the source, and couldn't find much documentation about it. I'd be glad for some heads up, I'm going to contribute some more documentation once I figure it all out. It's a very handy gem!

    ActionView::MissingTemplate

    After upgrading to Rails 3.2, my app gives a missing template error

    Missing partial /layouts/header with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder]}. Searched in:
      * "/Users/zach/development/waterfall2/themes/demo/views"
      * "/Users/zach/development/waterfall2/app/views"
      * "/Users/zach/.rvm/gems/ruby-1.9.3-p448@waterfall/gems/gmaps4rails-1.5.6/app/views"
      * "/Users/zach/.rvm/gems/ruby-1.9.3-p448@waterfall/gems/devise-1.5.4/app/views"
    

    when i move partials from themes/demo/views/layouts/ to app/views/layouts/ (both paths that it is searching in), the partials load and the page renders correctly. What might cause such an error?

    Theme with method

    I try this: theme :select_theme and bellow

    protected

    def select_theme
    'default'
    end

    But doesn't work.

    Anyone had same problem?

    The theme selector method is not invoked in some situations.

    I have theme_resolver method like this:

    class MyController < ApplicationController
      theme :theme_resolver
      # ...
      def show
        @current_user = ...
      end
    
    private
      def theme_resolver
        @current_user && @current_user.theme # or anything else that return a string. 
      end
    end

    The first time theme_resolver is invoked is prior to the action, so it returns nil.
    Next time it is invoked is at the time of render, at this time it is invoked as a method included in the my ActionView view. At this time the line (in common_methods.rb:12)

    self.respond_to?(@theme_name, true) ? self.send(@theme_name) : @theme_name.to_s

    returns nil, because self.respond_to?(@theme_name, true) evaluates to false because the theme_resolver is not member of the view (it's a member of the controller) so the theme_resolver is not invoked at all.
    I suggest changing that line to something like

    self.is_a? ActionView ? (self.controller.respond_to?(@theme_name, true) ? self.controller.send(@theme_name) : @theme_name.to_s)
      : (self.respond_to?(@theme_name, true) ? self.send(@theme_name) : @theme_name.to_s)

    or something like that.

    Meanwhile I have to invoke (as a workaround)

    theme theme_name

    to set and cache the theme_name before my action method reach the render code.

    Jarl

    Add theme_image_submit_tag

    Hi!

    Rails has helper image_submit_tag, but gem not. This is possible to add a code like this to implement: theme_image_submit_tag.
    "

    Displays an image which when clicked will submit the form.

    source is passed to AssetTagHelper#path_to_image

    ==== Options

    * :confirm => 'question?' - This will add a JavaScript confirm

    prompt with the question specified. If the user accepts, the form is

    processed normally, otherwise no action is taken.

    * :disabled - If set to true, the user will not be able to use this input.

    * Any other key creates standard HTML options for the tag.

    ==== Examples

    image_submit_tag("login.png")

    # =>

    image_submit_tag("purchase.png", :disabled => true)

    # =>

    image_submit_tag("search.png", :class => 'search_button')

    # =>

    image_submit_tag("agree.png", :disabled => true, :class => "agree_disagree_button")

    # =>

    def theme_image_submit_tag(source, options = {})
    options.stringify_keys!

    if confirm = options.delete("confirm")
      add_confirm_to_attributes!(options, confirm)
    end
    
    tag :input, { "type" => "image", "src" => theme_image_path(source) }.update(options.stringify_keys)
    

    end
    "
    There is only one difference at line: "tag :input, { "type" => "image", "src" => theme_image_path(source) }.update(options.stringify_keys) ", I am using theme_image_path rather that path_to_image. Do you need some extra info? I am ready to provide it (I have neve submit patch before, but ready if it is necessary some help will be provided if necessary). Are you planning to include this code into gem?

    Artem.

    Passing options to asset inclusion methods

    To allow for maximum flexibility, it would be nice if we could specify options to the asset inclusion tags which would then be forwarded to Rails' methods, so that the following, for example, is possible:

    theme_stylesheet_link_tag "blueprint/screen", :media => "screen, projection"
    theme_stylesheet_link_tag "blueprint/print", :media => "print"
    

    Here's a possible implementation:

    def theme_stylesheet_link_tag(file, *opts)
      stylesheet_link_tag theme_stylesheet_path(file), *opts
    end
    

    The ideal would be to able to use your methods transparently, as if we were using Rails' methods:

    theme_stylesheet_link_tag :all, :recursive => true
    theme_javascript_include_tag :defaults
    

    Liquid Support for Themes

    Dears,

    kindly, i was asking about supporting Liquid Templating in Themes_for_rails.
    and how to handle liquid templates inside themes.

    and also supporting other templating like Mustache and handlebars in themes.

    Problem with rspec view tests

    I'm using Rspec to test my application, but after I added the themes_for_rails and move my html.erb files to themes/my_theme/views folder my view tests dosn't works.

    The Rspec show me missing template error. There is a way to solve this problem? Or I'm doing something wrong?

    Thanks

    Support Helper per theme?

    is it available to write helper module per theme? for example the directory structure will be like this:

    • themes
      • business_theme
        • assets
        • views
        • helpers
          • application_helper.rb
          • home_helper.rb
          • more

    So the helpers which are inside theme would be isolated helper but still can access helper in app/helpers, if a method in app/helpers/application_helper.rb is already exist in themes/:name/helpers, it would use method in theme's helper.

    What do you think? is it good or bad idea?

    cheers,
    yacobus

    Get asset from non-current theme

    I tried this:

      <img src="<%= current_theme_image_path('small_logo.png', 'admin') %>"/>
    

    As per this in the sample page:

     current_theme_image_path('logo.png', 'purple')   # => /themes/purple/images/logo.png
    

    I only see this url helper (only takes asset):

       def current_theme_image_path(asset)
             image, extension = asset.split(".")
             base_theme_image_path(:theme => self.theme_name, :asset => "#{image}.#{extension}")
       end
    

    I was hoping to use this feature. Is it something that has been removed on purpose? Or perhaps I'm just using it wrong?
    Thanks for the awesome gem!

    Subfolders inside stylesheets folder

    Looks like themes_for_rails doesn't support subfolders within the stylesheets folder. I have a stylesheet which references an images folder inside the stylesheets folder. However, the stylesheet can't find the image file I'm trying to reference. When I visit the URL for the image like:

    http://my.site.com/themes/my_theme/stylesheets/images/my_image.png

    I get the following error:

    not found

    Illformed gemspec

    I get the following message on version 0.5.0:

    Invalid gemspec in [/Users/elia/.rvm/gems/ree-1.8.7-2011.03/specifications/themes_for_rails-0.5.0.gemspec]: Illformed requirement ["#<YAML::Syck::DefaultKey:0x105600030> 3.0.11"]
    

    conflict setting theme and layout

    Dears,

    i'm using theme for rails in my Rails3 Application with Devise.
    the problem is that devise can set custom layouts as follow :

    layout :layout_by_resource

    def layout_by_resource
    if devise_controller?
    "layout_name_for_devise"
    else
    "application"
    end
    end

    what if i'd like to set a theme in any of these conditions as follow :

    layout :layout_by_resource

    def layout_by_resource
    if devise_controller?
    "layout_name_for_devise"
    else
    theme "application"
    end
    end

    how this can be done please advise

    1.9 syntax used

    You should declare a 1.9 only compatibility in the gem spec or (preferably) make it 1.8 friendly

    The "offending" line is this:

    SyntaxError: /Users/elia/Code/Mikamai/pradagroup-html/vendor/gems/themes_for_rails/lib/themes_for_rails/action_view.rb:48: syntax error, unexpected tIDENTIFIER, expecting tAMPER
          javascript_include_tag(*files, options)
                                                ^
    

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. 📊📈🎉

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google ❤️ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.