Class: SiSU_Markup::MarkupIdentify

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/sst_identify_markup.rb

Instance Method Summary collapse

Constructor Details

#initialize(opt) ⇒ MarkupIdentify

Returns a new instance of MarkupIdentify.



80
81
82
83
# File 'lib/sisu/sst_identify_markup.rb', line 80

def initialize(opt)
  @opt=opt
  @description='This is a script attempts to identify the version of markup used in SiSU (and provides information on changes in markup)'
end

Instance Method Details

#determine_markup_versionObject



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/sisu/sst_identify_markup.rb', line 213

def determine_markup_version
  if @opt.fns.nil? \
  or @opt.fns.empty?
    MarkupHistory.new(@opt).help_identify
  end
  if File.exist?(@opt.fns)
    if @opt.fns =~/\.(?:sst|ssm|ssi|s[123i]|r[123])/
      markup=identify #(@opt.fns)
      if defined? markup.version
        unless @opt.act[:quiet][:set]==:on
          message=unless markup.declared_version.empty?
            "#{@opt.fns}\n  markup Type Declared as SiSU #{markup.declared_version} #{markup.declared_type}\n  appears to be SiSU #{markup.version}"
          else
            "Markup Type Appears to be SiSU #{markup.version}\n  in file #{@opt.fns}"
          end
          puts message
          puts %{"sisu --query-#{markup.version}" for a brief description of markup type}
        end
      end
    else puts 'file-type not recognised: ' + @opt.fns
    end
  else puts 'file not found: ' + @opt.fns
  end
  (defined? markup.version) \
  ? markup.version
  : 'markup type/version not determined'
end

#helpObject



84
85
86
87
88
89
90
91
# File 'lib/sisu/sst_identify_markup.rb', line 84

def help
print <<WOK

#{@description}

WOK
  exit
end

#identifyObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/sisu/sst_identify_markup.rb', line 92

def identify
  f=@opt.fns
  if f =~/(?:\.sst|\.ssm|\.ssi|\.s[123])$/ \
  and File.exist?(f)
    file=File.open(f,'r')
    cont=file.readlines
    file.close
    links,oldlinks='',''
    markup=nil
    @declared_type,@declared_markup='[text?]',''
    if cont[0] =~ /^(?:%\s+)?SiSU\s+(text|master|insert)\s+([0-9](?:\.[0-9]+){1,2})/ \
    or cont[0] =~ /^(?:%\s+)?sisu-([0-9](?:\.[0-9]+){1,2})/
      @declared_type,@declared_markup=$1,$2
    elsif cont[0] =~ /^(?:%\s+)?SiSU\s+([0-9](?:\.[0-9]+){1,2})/ \
    or cont[0] =~ /^(?:%\s+)?sisu-([0-9](?:\.[0-9]+){1,2})/
      @declared_markup=$1
    end
    @flag_2_0,@flag_1_0,@flag_69,@flag_66,@flag_57,@flag_38=false,false,false,false,false,false
    cont.each_with_index do |y,i|
      if y =~/^(?:0\{?~links?|@links?:)\s/ \
      and f =~/(?:\.sst|\.ssm|\.ssi|\.s[123])/
        links=unless y =~/\{.+?\}\S+/; oldlinks=' (pre 0.20.4 header links)'
        else ' (post 0.20.4 header links)'
        end
      end
      if @flag_2_0 \
      or y =~/^@make:|^@classify|^\s\s?:[a-z_-]+?:\s+\S/
        version=2.0.to_f
        markup=MarkupInform.new(version,'2.0' + oldlinks,@declared_markup,@declared_type)
        @flag_2_0=true
        break
      end
      unless @flag_38
        if (y =~/^:?A~/ and f =~/(?:\.sst|\.ssm|\.ssi)/)
          version='0.38'
          markup=MarkupInform.new(version,'0.38' + oldlinks,@declared_markup,@declared_type)
          @flag_38=true
        end
      end
      if @flag_38
        if @flag_1_0 \
        or y =~/^=\{.+?\}\s*$/
          version='0.69'
          markup=MarkupInform.new(version,'0.69' + oldlinks,@declared_markup,@declared_type)
          @flag_1_0=true
          break
        end
        if @flag_66 \
        or y =~/[a-z+][:;]\{.+?\}[:;][a-z+]/
          version='0.66'
          markup=MarkupInform.new(version,'0.66' + oldlinks,@declared_markup,@declared_type)
          @flag_66=true
          break
        end
      end
    end
    unless @flag_2_0 \
    or @flag_1_0 \
    or @flag_66
      cont.each_with_index do |y,i|
        if y =~/^(?:0\{?~links?|@links?:)\s/ \
        and f =~/(?:\.sst|\.ssm|\.ssi|\.s[123])/
          links=unless y =~/\{.+?\}\S+/; oldlinks=' (pre 0.20.4 header links)'
          else ' (post 0.20.4 header links)'
          end
        end
        if @flag_57 \
        or (y =~/^:?A~\?? @title/ and f =~/(?:\.sst|\.ssm|\.ssi)/)
          version='0.57'
          markup=MarkupInform.new(version,'0.57' + oldlinks,@declared_markup,@declared_type)
          @flag_57=true
          break
        end
        if @flag_38 \
        or (y =~/^:?A~/ and f =~/(?:\.sst|\.ssm|\.ssi)/)
          version='0.38'
          markup=MarkupInform.new(version,'0.38' + oldlinks,@declared_markup,@declared_type)
          @flag_38=true
          break if i >= 200
          if y =~ /(?:~{\*+|~\[\*|~\[\+)\s/
            version='0.42'
            markup=MarkupInform.new(version,'0.42' + oldlinks,@declared_markup,@declared_type)
            break
          end
        end
        if (y =~/^1~/ and f =~/(?:\.sst|\.ssm|\.ssi)/) \
        and not @flag_38
          version='0.37'
          markup=MarkupInform.new(version,'0.37 is substantially 0.16 - 0.36 markup with new file-extension' + oldlinks,@declared_markup,@declared_type)
          break
        end
        if y =~/^1~/ \
        and f =~/\.([rs])([123])/ \
        and not @flag_38
          t,n=$1,$2
          version='0.16'
          instruct=if t =~/r/
            " (change file extension from .#{t}#{n} to .ssm)"
          else " (change file extension from .#{t}#{n} to .sst)"
          end
          markup=MarkupInform.new(version,'0.16 - 0.36' + instruct + links,@declared_markup,@declared_type)
          break
        end
        if y =~/^0\{~/ \
        and not @flag_38
          version='0.1'
          markup=MarkupInform.new(version,'0.1 - 0.15',@declared_markup,@declared_type)
          break
        end
        if y =~/^0\{{3}/ \
        and not @flag_38
          markup=MarkupInform.new('circa. 1997','old, check date',@declared_markup,@declared_type)
          break
        end
        markup='Not a recognised file type '
      end
    end
    markup
  else MarkupHistory.new(@opt).help_query
  end
end

#markup_version?Boolean

Returns:

  • (Boolean)


240
241
242
243
244
245
246
247
248
# File 'lib/sisu/sst_identify_markup.rb', line 240

def markup_version?
  if @opt.fns.empty?
    @opt.files.each do |fns|
      @opt.fns=fns
      determine_markup_version
    end
  else determine_markup_version
  end
end