Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ meet your needs:
Please note that the maintainers of Scenic make no assertions about the
quality or security of the above adapters.

**Can I use Scenic in Rails engines?**

Yes, just update the path where Scenic looks up its views in its configuration:

```ruby
Scenic.configure do |config|
config.root_path = MyEngine.root
end
```

## About

Scenic is maintained by [Derek Prior], [Caleb Hearth], and you, our
Expand Down
8 changes: 8 additions & 0 deletions lib/scenic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ def self.load
def self.database
configuration.database
end

# The path where Scenic looks up its views
#
# This default to {Rails.root} but can be overridden
# via {Configuration}.
def self.root_path
configuration.root_path
end
end
4 changes: 3 additions & 1 deletion lib/scenic/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ class Configuration
#
# Defaults to an instance of {Adapters::Postgres}
# @return Scenic adapter
attr_accessor :database
attr_accessor :database, :root_path

def initialize
@database = Scenic::Adapters::Postgres.new
@root_path = Rails.root
end
end

Expand All @@ -29,6 +30,7 @@ def self.configuration=(config)
# ```
# Scenic.configure do |config|
# config.database = Scenic::Adapters::Postgres.new
# config.root_path = MyEngine.root
# end
# ```
def self.configure
Expand Down
2 changes: 1 addition & 1 deletion lib/scenic/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def to_sql
end

def full_path
Rails.root.join(path)
Pathname.new(File.join(Scenic.root_path, path))
end

def path
Expand Down
4 changes: 3 additions & 1 deletion spec/support/generator_spec_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
RSpec.configure do |config|
config.before(:example, :generator) do
fake_rails_root = File.expand_path("../../tmp", __dir__)
allow(Rails).to receive(:root).and_return(Pathname.new(fake_rails_root))
fake_rails_root_pathname = Pathname.new(fake_rails_root)
allow(Rails).to receive(:root).and_return(fake_rails_root_pathname)
allow(Scenic).to receive(:root_path).and_return(fake_rails_root_pathname)

destination fake_rails_root
prepare_destination
Expand Down