jdvp-codetabs-commonmark 0.1.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jdvp-codetabs-commonmark.rb +28 -17
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f65f09333732d5d41b11e9a5bbd7bb4b0e1cb109f8fa19fab667d865cf09155
4
- data.tar.gz: 646292f139c1041ae813f000799257165e2c280dfe7b289481b85205d89a03fb
3
+ metadata.gz: 30860da3f4f60c629ca9dcd82590c34f49fb731d2fc6d32322088358e22c9d3a
4
+ data.tar.gz: ac41c3be00aab2a260f54f89eca0b6a4515b258b0b13bbd1fcbfaa8ca22dde76
5
5
  SHA512:
6
- metadata.gz: de762de8163ea00d98c5396149a638bafcee06db0a21d4567d7d396bdbd60b02db58e4e18c0ba2f3d24fb15acfc4dbdefa2bd69ada6c4dfe267ca718d8bd33d7
7
- data.tar.gz: 21902c1194e42541540ea2ed4c2a0b377c82891039b3e95271910d909f44040fc0f6921b233eb9672a2ae22ed84608f47fbb9dbbf67cd94ada6a7f1a1cd8b87b
6
+ metadata.gz: b7cdfe14cc645b1bb36a539f05b7d71564b1552d467826c700a8f0b5781c9e1d98bac8b9bb802bbba46f11af998eafef56264dc50e25badc664915de5587788e
7
+ data.tar.gz: f036418139859a0f63bc0fa4254f1e6885155e893bedc499d233b6c28ee861048e72ab4b315ed9d9ef4b8b4d646423583fd0a7948e560701716d26c990683167
@@ -4,22 +4,8 @@ require "jekyll"
4
4
  require "securerandom"
5
5
 
6
6
  class CodeTabsCustomerRenderer < JekyllCommonMarkCustomRenderer
7
- @added_assets_links = false
8
7
  @added_copy_snackbar = false
9
8
 
10
- def render(node)
11
- if node.type == :document
12
- if (!@added_assets_links)
13
- #Add references to the fonts, css, and js required
14
- out("<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Roboto+Mono\"/>")
15
- out("<link rel=\"stylesheet\" href=\"JdvpCodeTabs-baseurl/assets/codeblock.css\"/>")
16
- out("<script src=\"JdvpCodeTabs-baseurl/assets/codeblock.js\"></script>")
17
- @added_assets_links = true
18
- end
19
- end
20
- super(node)
21
- end
22
-
23
9
  def code_block(node)
24
10
  #Determine what objects this code block is surrounded by.
25
11
  previous_node_type = node&.previous&.type&.to_s
@@ -144,9 +130,31 @@ class Jekyll::Converters::Markdown
144
130
  end
145
131
  end
146
132
 
147
- Jekyll::Hooks.register :posts, :post_convert do |post|
148
- if post.content.include? "JdvpCodeTabs-baseurl"
149
- post.content = post.content.gsub("JdvpCodeTabs-baseurl", "#{post.site.baseurl}")
133
+ def get_resource_string(site)
134
+ return "<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Roboto+Mono\"/>" +
135
+ "<link rel=\"stylesheet\" href=\"#{site.baseurl}/assets/codeblock.css\"/>" +
136
+ "<script src=\"#{site.baseurl}/assets/codeblock.js\"></script>"
137
+ end
138
+
139
+ def add_resource_links_in_html_head(site)
140
+ site_directory = "#{site.in_dest_dir("/")}"
141
+
142
+ # For every html file in the generated site
143
+ Dir.glob("*.html", base: site_directory).each do |file_name|
144
+ file_plus_path = "#{site_directory}#{file_name}"
145
+
146
+ # Check if the file contains a code switcher and skip it if it does not
147
+ if (!File.foreach(file_plus_path).grep(/code_switcher_container_parent/).any?)
148
+ next
149
+ end
150
+
151
+ # If the file has a code switcher and a head element, add the resource links to the end of the head element
152
+ if (File.foreach(file_plus_path).grep(/<\/head>/).any?)
153
+ File.write(file_plus_path, File.open(file_plus_path, &:read).sub("</head>","#{get_resource_string(site)}</head>"))
154
+ # Otherwise if it has a html element add a head element with the resource links
155
+ elsif (File.foreach(file_plus_path).grep(/<\/html>/).any?)
156
+ File.write(file_plus_path, File.open(file_plus_path, &:read).sub(/(<html.*>)/,"#{$1}<head>#{get_resource_string(site)}</head>"))
157
+ end
150
158
  end
151
159
  end
152
160
 
@@ -166,4 +174,7 @@ Jekyll::Hooks.register :site, :post_write do |site|
166
174
  FileUtils.cp(copy_icon, "#{site.in_dest_dir("assets/icon_copy.svg")}")
167
175
  theme_icon = File.expand_path("../../assets/icon_theme.svg", __FILE__)
168
176
  FileUtils.cp(theme_icon, "#{site.in_dest_dir("assets/icon_theme.svg")}")
177
+
178
+ #Add CSS & JS references to files that use code tabs
179
+ add_resource_links_in_html_head(site)
169
180
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jdvp-codetabs-commonmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JD Porterfield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-22 00:00:00.000000000 Z
11
+ date: 2023-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: securerandom