Class: Ecrire::Theme::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/ecrire/theme/engine.rb

Overview

Engine is the foundation of Rails. It can be used to encapsulate part of the application and this is exactly what it does here.

Ecrire::Theme::Engine is the block that hooks into Ecrire::Application to provide Theme support.

This class is the only element that the Gem includes at runtime.

Everything else is defined in the user’s theme folder.

This engine is the reason why it’s possible to have Ecrire as a gem and theme as user’s folder.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#post_pathObject

post_path needs to be defined so Ecrire can link from the admin to a post. This is also needed when listing all the titles a post has and the URL they represent.



32
33
34
# File 'lib/ecrire/theme/engine.rb', line 32

def post_path
  @post_path
end

Instance Method Details

#has_migrations?Boolean

Disables migration for now. Any Rails::Engine instance can support migrations which means that Theme could have their own models.

It’s likely that at some point this behavior is resumed but I want to make sure that I understand the implication before turning this back on.

For example, I would like to make sure that the Admin is shelled from those future migrations.

Returns:

  • (Boolean)


79
80
81
# File 'lib/ecrire/theme/engine.rb', line 79

def has_migrations?
  false
end

#pathsObject

Return paths for a theme. The paths follow the structure of the default theme.

It creates a new Rails::Paths because it’s highly customized and it was less readable to disable and changes every paths.

This could be modified in the user’s theme.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ecrire/theme/engine.rb', line 45

def paths
  @paths ||= begin
    paths = Rails::Paths::Root.new(Ecrire::Theme.path)
    paths.add 'app/views', with: 'views'
    paths.add 'app/controllers', with: 'controllers', eager_load: true
    paths.add 'app/assets', with: 'assets', glob: '*'
    paths.add 'app/helpers', with: 'helpers', eager_load: true

    paths.add 'config/routes.rb', with: 'routes.rb'
    paths.add 'config/locales', with: 'locales', glob: '**/*.{rb,yml}'
    paths.add 'config/environments', with: 'environments', glob: "#{Rails.env}.rb"

    paths.add 'public', with: 'tmp/public'

    paths.add "lib/assets",          glob: "*"
    paths.add "vendor/assets",       glob: "*"
    paths.add "lib/tasks"

    paths
  end
end

#root_path(file = 'config.ru') ⇒ Object

Return the root_path for the current theme

The method starts at the current working directory and moves from parent to parent until it either finds config.ru or it reaches the root.

Raise an error if it reaches the root and can’t find config.ru.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ecrire/theme/engine.rb', line 91

def root_path(file = 'config.ru')
  begin
    pathname = Pathname.pwd

    while !(pathname + file).exist? do
      pathname = pathname.parent
      if pathname.root?
        raise "Could not find #{file}. Type 'ecrire new blog_name' to create a new blog"
        break
      end
    end

    pathname
  end
end