Module: Generators::MarkUp

Included in:
ContextUser, HtmlMethod, MERBGenerator
Defined in:
lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb,
lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb

Overview

Handle common markup tasks for the various Html classes

Instance Method Summary collapse

Instance Method Details

#cvs_url(url, full_path) ⇒ Object

Build a webcvs URL with the given ‘url’ argument. URLs with a ‘%s’ in them get the file’s path sprintfed into them; otherwise they’re just catenated together.



248
249
250
251
252
253
254
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 248

def cvs_url(url, full_path)
    if /%s/ =~ url
        return sprintf( url, full_path )
    else
        return url + full_path
    end
end

#markup(str, remove_para = false) ⇒ Object

Convert a string in markup format into HTML. We keep a cached SimpleMarkup object lying around after the first time we’re called per object.



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 197

def markup(str, remove_para=false)
    return '' unless str
    unless defined? @markup
        @markup = SM::SimpleMarkup.new

        # class names, variable names, file names, or instance variables
        @markup.add_special(/(
        \b([A-Z]\w*(::\w+)*[.\#]\w+)  #    A::B.meth
        | \b([A-Z]\w+(::\w+)*)       #    A::B..
        | \#\w+[!?=]?                #    #meth_name 
        | \b\w+([_\/\.]+\w+)+[!?=]?  #    meth_name
        )/x, :CROSSREF)

        # external hyperlinks
        @markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)

        # and links of the form  <text>[<url>]
        @markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\.\S+?\])/, :TIDYLINK)
        #        @markup.add_special(/\b(\S+?\[\S+?\.\S+?\])/, :TIDYLINK)

    end
    unless defined? @html_formatter
        @html_formatter = HyperlinkHtml.new(self.path, self)
    end

    # Convert leading comment markers to spaces, but only
    # if all non-blank lines have them

    if str =~ /^(?>\s*)[^\#]/
        content = str
    else
        content = str.gsub(/^\s*(#+)/)  { $1.tr('#',' ') }
    end

    res = @markup.convert(content, @html_formatter)
    if remove_para
        res.sub!(/^<p>/, '')
        res.sub!(/<\/p>$/, '')
    end
    res
end

#style_url(path, css_name = nil) ⇒ Object



240
241
242
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 240

def style_url(path, css_name=nil)
    css_name ||= CSS_NAME      
end