Skip to content

Commit

Permalink
Expose reps and paths in shell command
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Oct 23, 2016
1 parent a37471f commit c8b257b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
19 changes: 16 additions & 3 deletions lib/nanoc/cli/commands/shell.rb
Expand Up @@ -22,10 +22,23 @@ def env
end

def self.env_for_site(site)
action_provider = Nanoc::Int::ActionProvider.named(:rule_dsl).for(site)
reps = Nanoc::Int::ItemRepRepo.new
builder = Nanoc::Int::ItemRepBuilder.new(site, action_provider, reps)
builder.run

view_context =
Nanoc::ViewContext.new(
reps: reps,
items: site.items,
dependency_tracker: Nanoc::Int::DependencyTracker::Null.new,
compiler: nil,
)

{
items: Nanoc::ItemCollectionWithRepsView.new(site.items, nil),
layouts: Nanoc::LayoutCollectionView.new(site.layouts, nil),
config: Nanoc::ConfigView.new(site.config, nil),
items: Nanoc::ItemCollectionWithRepsView.new(site.items, view_context),
layouts: Nanoc::LayoutCollectionView.new(site.layouts, view_context),
config: Nanoc::ConfigView.new(site.config, view_context),
}
end
end
Expand Down
31 changes: 25 additions & 6 deletions spec/nanoc/cli/commands/shell_spec.rb
Expand Up @@ -17,19 +17,38 @@
describe '#env_for_site' do
subject { described_class.env_for_site(site) }

before do
File.write('content/hello.md', 'Hello!')
File.write('layouts/default.erb', '<title>MY SITE!</title><%= yield %>')
end

let(:site) do
double(
:site,
items: [],
layouts: [],
config: nil,
)
Nanoc::Int::SiteLoader.new.new_from_cwd
end

it 'returns views' do
expect(subject[:items]).to be_a(Nanoc::ItemCollectionWithRepsView)
expect(subject[:layouts]).to be_a(Nanoc::LayoutCollectionView)
expect(subject[:config]).to be_a(Nanoc::ConfigView)
end

it 'returns correct items' do
expect(subject[:items].size).to eq(1)
expect(subject[:items].first.identifier.to_s).to eq('/hello.md')
end

it 'returns correct layouts' do
expect(subject[:layouts].size).to eq(1)
expect(subject[:layouts].first.identifier.to_s).to eq('/default.erb')
end

it 'returns items with reps' do
expect(subject[:items].first.reps).not_to be_nil
expect(subject[:items].first.reps.first.name).to eq(:default)
end

it 'returns items with rep paths' do
expect(subject[:items].first.reps.first.path).to eq('/hello.md')
end
end
end

0 comments on commit c8b257b

Please sign in to comment.