Top Level Namespace

Defined Under Namespace

Classes: CodeTabsCustomerRenderer

Instance Method Summary collapse

Instance Method Details



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/jdvp-codetabs-commonmark.rb', line 139

def add_resource_links_in_html_head(site)
  site_directory = "#{site.in_dest_dir("/")}"

  # For every html file in the generated site 
  Dir.glob("*.html", base: site_directory).each do |file_name|
    file_plus_path = "#{site_directory}#{file_name}"

    # Check if the file contains a code switcher and skip it if it does not
    if (!File.foreach(file_plus_path).grep(/code_switcher_container_parent/).any?)
      next
    end

    # If the file has a code switcher and a head element, add the resource links to the end of the head element
    if (File.foreach(file_plus_path).grep(/<\/head>/).any?)
      File.write(file_plus_path, File.open(file_plus_path, &:read).sub("</head>","#{get_resource_string(site)}</head>"))
    # Otherwise if it has a html element add a head element with the resource links
    elsif (File.foreach(file_plus_path).grep(/<\/html>/).any?)
      File.write(file_plus_path, File.open(file_plus_path, &:read).sub(/(<html.*>)/,"#{$1}<head>#{get_resource_string(site)}</head>"))
    end
  end
end

#get_resource_string(site) ⇒ Object



133
134
135
136
137
# File 'lib/jdvp-codetabs-commonmark.rb', line 133

def get_resource_string(site)
 return "<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Roboto+Mono\"/>" +
        "<link rel=\"stylesheet\" href=\"#{site.baseurl}/assets/codeblock.css\"/>" +
        "<script src=\"#{site.baseurl}/assets/codeblock.js\"></script>"
end