Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jun 11, 2016
1 parent 44d3295 commit 11dfe28
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/nanoc/base/entities.rb
@@ -1,5 +1,7 @@
require_relative 'entities/identifier'
require_relative 'entities/content'
require_relative 'entities/rule_memory_action'
require_relative 'entities/rule_memory_actions'

require_relative 'entities/code_snippet'
require_relative 'entities/configuration'
Expand All @@ -11,7 +13,5 @@
require_relative 'entities/layout'
require_relative 'entities/pattern'
require_relative 'entities/rule_memory'
require_relative 'entities/rule_memory_action'
require_relative 'entities/rule_memory_actions'
require_relative 'entities/site'
require_relative 'entities/snapshot_def'
2 changes: 1 addition & 1 deletion lib/nanoc/base/entities/identifiable_collection.rb
@@ -1,8 +1,8 @@
module Nanoc::Int
# @api private
class IdentifiableCollection
include Enumerable
include Contracts::Core
include Enumerable

extend Forwardable

Expand Down
16 changes: 16 additions & 0 deletions lib/nanoc/base/entities/rule_memory.rb
@@ -1,47 +1,63 @@
module Nanoc::Int
class RuleMemory
include Contracts::Core
include Enumerable

C = Contracts

def initialize(item_rep)
@item_rep = item_rep
@actions = []
end

Contract C::None => Numeric
def size
@actions.size
end

Contract Numeric => C::Maybe[Nanoc::Int::RuleMemoryAction]
def [](idx)
@actions[idx]
end

Contract Symbol, Hash => self
def add_filter(filter_name, params)
@actions << Nanoc::Int::RuleMemoryActions::Filter.new(filter_name, params)
self
end

Contract String, C::Maybe[Hash] => self
def add_layout(layout_identifier, params)
@actions << Nanoc::Int::RuleMemoryActions::Layout.new(layout_identifier, params)
self
end

Contract Symbol, C::Bool, C::Maybe[String] => self
def add_snapshot(snapshot_name, final, path)
will_add_snapshot(snapshot_name) if final
@actions << Nanoc::Int::RuleMemoryActions::Snapshot.new(snapshot_name, final, path)
self
end

Contract C::None => C::ArrayOf[Nanoc::Int::RuleMemoryAction]
def snapshot_actions
@actions.select { |a| a.is_a?(Nanoc::Int::RuleMemoryActions::Snapshot) }
end

Contract C::None => C::Bool
def any_layouts?
@actions.any? { |a| a.is_a?(Nanoc::Int::RuleMemoryActions::Layout) }
end

# TODO: Add contract
def serialize
map(&:serialize)
end

Contract C::Func[Nanoc::Int::RuleMemoryAction => C::Any] => self
def each
@actions.each { |a| yield(a) }
self
end

private
Expand Down
12 changes: 12 additions & 0 deletions lib/nanoc/base/entities/site.rb
@@ -1,8 +1,13 @@
module Nanoc::Int
# @api private
class Site
include Contracts::Core

C = Contracts

attr_accessor :compiler

Contract C::KeywordArgs[config: Nanoc::Int::Configuration, code_snippets: C::RespondTo[:each], items: C::RespondTo[:each], layouts: C::RespondTo[:each]] => C::Any
# @param [Nanoc::Int::Configuration] config
# @param [Enumerable<Nanoc::Int::CodeSnippet>] code_snippets
# @param [Enumerable<Nanoc::Int::Item>] items
Expand All @@ -17,15 +22,18 @@ def initialize(config:, code_snippets:, items:, layouts:)
ensure_identifier_uniqueness(@layouts, 'layout')
end

Contract C::None => self
# Compiles the site.
#
# @return [void]
#
# @since 3.2.0
def compile
compiler.run_all
self
end

Contract C::None => Nanoc::Int::Compiler
# Returns the compiler for this site. Will create a new compiler if none
# exists yet.
#
Expand All @@ -39,6 +47,7 @@ def compiler
attr_reader :items
attr_reader :layouts

Contract C::None => self
# Prevents all further modifications to itself, its items, its layouts etc.
#
# @return [void]
Expand All @@ -47,8 +56,10 @@ def freeze
items.freeze
layouts.freeze
code_snippets.__nanoc_freeze_recursively
self
end

Contract C::RespondTo[:each], String => self
def ensure_identifier_uniqueness(objects, type)
seen = Set.new
objects.each do |obj|
Expand All @@ -57,6 +68,7 @@ def ensure_identifier_uniqueness(objects, type)
end
seen << obj.identifier
end
self
end
end
end
6 changes: 6 additions & 0 deletions lib/nanoc/base/entities/snapshot_def.rb
@@ -1,13 +1,19 @@
module Nanoc
module Int
class SnapshotDef
include Contracts::Core

C = Contracts

attr_reader :name

Contract Symbol, C::Bool => C::Any
def initialize(name, is_final)
@name = name
@is_final = is_final
end

Contract C::None => C::Bool
def final?
@is_final
end
Expand Down

0 comments on commit 11dfe28

Please sign in to comment.