Giter VIP home page Giter VIP logo

Comments (9)

yogeshjain999 avatar yogeshjain999 commented on August 17, 2024

As given in the README, you could either define method or Proc for this in the controller.

theme :default_theme

private

def default_theme
  theme || parent_theme || "layout_name"
end

from themes_on_rails.

iamdriz avatar iamdriz commented on August 17, 2024

@yogeshjain999 So you pass the default layout as the fallback theme?

from themes_on_rails.

yogeshjain999 avatar yogeshjain999 commented on August 17, 2024

Correct @iamdriz. It is because search locations includes app/themes and app/views Dir.

from themes_on_rails.

iamdriz avatar iamdriz commented on August 17, 2024

@yogeshjain999 That being said though.... If I have:

theme :theme_resolver

private

def theme_resolver
  'a_theme_that_doesnt_exist' || 'a_theme_that_does_exist' || 'application'
end

I'm finding that instead of it falling back to the 'a_theme_that_does_exist' it falls straight back to the default views. Probably because I have a value for the first theme (even though it doesn't exist) in the operator and it will try and find that and then just fallback... what I want it to do is fallback on a view-basis to the next operator value and then the default views if those can't be found either. To achieve that, would I need to manually check if the view requested existed first based on the currently requested theme and then try the next one until defaulting to application?

from themes_on_rails.

yogeshjain999 avatar yogeshjain999 commented on August 17, 2024

That being said, easiest way I can see is doing it like,

def theme_resolver
  theme_present?('a_theme_that_doesnt_exist') || 'application'
end

def theme_present?(name)
  return name if Rails.application.paths["app/themes/#{name}"].present?
end

from themes_on_rails.

iamdriz avatar iamdriz commented on August 17, 2024

@yogeshjain999 The theme may exist but the view for that particular request may not.

from themes_on_rails.

iamdriz avatar iamdriz commented on August 17, 2024

In order to get the fallback theme to work I had to do:

before_action :fallback_theme
def fallback_theme
  self.prepend_view_path 'app/themes/fallback_theme/views'
end

from themes_on_rails.

iamdriz avatar iamdriz commented on August 17, 2024

It also turns out that it doesn't actually use the fallback string:

def theme_resolver
  params[:theme] || 'I CAN PUT ANYTHING HERE'
end

So it would be good to pass back a nil if no theme is specified. Rather than a string that is basically ignored as the default paths are already in the view_paths. Just feels a bit of a hack.

from themes_on_rails.

iamdriz avatar iamdriz commented on August 17, 2024

After playing around with this I've come to find that building a Rails Engine is probably a better way forward as then it means you can have everything a Rails app would have on a theme basis.

from themes_on_rails.

Related Issues (20)

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.