lib/germinate/hunk.rb in devver-germinate-1.0.1 vs lib/germinate/hunk.rb in devver-germinate-1.1.0
- old
+ new
@@ -1,6 +1,8 @@
+require 'pathname'
require 'ick'
+require 'fattr'
require File.expand_path("shared_style_attributes", File.dirname(__FILE__))
# A Hunk represents a chunk of content. There are different types of Hunk, like
# Code or Text, which may be formatted differently by the Formatter. At its
# most basic a Hunk is just a list of Strings, each one representing a single
@@ -9,11 +11,11 @@
include Germinate::SharedStyleAttributes
Ick::Returning.belongs_to(self)
def initialize(contents=[], template = {})
super(contents)
- copy_shared_style_attrubutes_from(template)
+ copy_shared_style_attributes_from(template)
end
# return a copy with leading and trailing whitespace lines removed
def strip
Germinate::TextTransforms.strip_blanks.call(self)
@@ -49,19 +51,19 @@
end
def [](*args)
returning(super) do |slice|
if slice.kind_of?(Germinate::Hunk)
- slice.copy_shared_style_attrubutes_from(self)
+ slice.copy_shared_style_attributes_from(self)
end
end
end
def slice(*args)
returning(super) do |slice|
if slice.kind_of?(Germinate::Hunk)
- slice.copy_shared_style_attrubutes_from(self)
+ slice.copy_shared_style_attributes_from(self)
end
end
end
def index_matching(pattern, start_index=0)
@@ -69,10 +71,14 @@
return i if pattern === self[i]
}
nil
end
+ def whole_file?
+ false
+ end
+
private
def resolved?
!unresolved_hunks?
end
@@ -111,18 +117,20 @@
end
end
end
+# Represents a hunk of article text
class Germinate::TextHunk < Germinate::Hunk
def format_with(formatter)
super(formatter) do |formatter|
formatter.format_text!(self, comment_prefix)
end
end
end
+# Represents a hunk of source code
class Germinate::CodeHunk < Germinate::Hunk
def code_open_bracket=(new_value)
super
end
@@ -137,7 +145,19 @@
end
end
end
class Germinate::NullHunk < Germinate::Hunk
+end
+
+# Represents a the entire text of a file on disk
+class Germinate::FileHunk < Germinate::CodeHunk
+ def initialize(lines, template)
+ super(lines, template)
+ raise ArgumentError, "Path required" if source_path.nil?
+ end
+
+ def whole_file?
+ true
+ end
end