# self.options = Onebox.options[self.class.name.split("::").last.to_s] #We can use this a more generic approach. extract the engine class name automatically
self.options=DEFAULTS
@selected_lines_array=nil
@selected_one_liner=0
@model_file=nil
# Define constant after merging options set in Onebox.options
from=1iffrom>contents_lines_size#if "from" out of TOP bound set to 1st line
to=contents_lines_sizeifto>contents_lines_size#if "to" is out of TOP bound set to last line.
ifone_liner
@selected_one_liner=from
ifEXPAND_ONE_LINER!=EXPAND_NONE
if(EXPAND_ONE_LINER&EXPAND_BEFORE!=0)# check if EXPAND_BEFORE flag is on
from=[1,from-LINES_BEFORE].max# make sure expand before does not go out of bound
end
if(EXPAND_ONE_LINER&EXPAND_AFTER!=0)# check if EXPAND_FLAG flag is on
to=[to+LINES_AFTER,contents_lines_size].min# make sure expand after does not go out of bound
end
from=contents_lines_sizeiffrom>contents_lines_size#if "from" is out of the content top bound
# to = contents_lines_size if to > contents_lines_size #if "to" is out of the content top bound
else
#no expand show the one liner solely
end
end
ifto-from>MAX_LINES&&!one_liner#if exceed the MAX_LINES limit correct unless range was produced by one_liner which it expand setting will allow exceeding the line limit
truncated=true
to=from+MAX_LINES-1
end
{
from:from,#calculated from
from_minus_one:from-1,#used for getting currect ol>li numbering with css used in template
to:to,#calculated to
one_liner:one_liner,#boolean if a one-liner
selected_one_liner:@selected_one_liner,#if a one liner is provided we create a reference for it.
range_provided:range_provided,#boolean if range provided
truncated:truncated,
}
end
#minimize/compact leading indentation while preserving overall indentation
unlessm.nil?||l.size==m[0].size||l.size==0# no match | only spaces in line | empty line
m_str_length=m[0].size
ifm_str_length<=1# minimum space is 1 or nothing we can break we found our minimum
min_space=m_str_length
break#stop iteration
end
min_space=m_str_lengthifm_str_length<min_space
else
next# SKIP no match or line is only spaces
end
end
a_lines.eachdo|l|
re=Regexp.new"^[ ]{#{min_space}}"#match the minimum spaces of the line
l.gsub!(re,"")
end
a_lines.join
end
defline_number_helper(lines,start,selected)
lines=removeLeadingIndentation(lines.join).lines# A little ineffeicent we could modify removeLeadingIndentation to accept array and return array, but for now it is only working with a string