github-to-canvas 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18f61edcbd53e1e26f59fe6767ae09b3bb227dee2f6529797a1f0fc6ace94b00
4
- data.tar.gz: 0757bd6b39a7fd9e4bb996156db33309cd96afbe2f8274c1261e95b4aad210e4
3
+ metadata.gz: 71e183a1ea3659fdc71af9af4c1ce0370be119f4241e8773ac82fdee9400cf48
4
+ data.tar.gz: ce08e0ec8f3f64471a4966a955e454d8a25cd95e9b9555dd61ca550ec77fe41b
5
5
  SHA512:
6
- metadata.gz: 593e15eb02ee30c7d45b3ffb479efcd69ab3b80436a23b81f6f731e3ad7a2a3a81d05601baf15cd893a86a54029a919ac45617a20cdb4a2c5ad4e441b8529c4e
7
- data.tar.gz: 8306e5d652b5e61c3aba33e09a70e0f8aa3a1455dea60269c685983793c443f7065944cf157aa365c693cec9ae12d49a579aec66efc73e390e2643c3fa07b198
6
+ metadata.gz: 2b04300b61b6301f32512ca328f27affaa186082e0e35d8eeab7c748b77ba3c10a07a7309ba1d3e92563007910da3c9e70a7a1db37ce184b48763cc8d455ffb7
7
+ data.tar.gz: 2cbe19f6cd61338619072f9f07e215762ce45ffbd3b3aa0672d3f77a1c3bd3a8e7837b5e237bf6b01bd4058ac05afaf5c547b82c1b829a8787b344c88fc21276
data/bin/github-to-canvas CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'byebug'
4
3
 
5
4
  require 'optparse'
6
5
  require 'github-to-canvas'
@@ -78,7 +77,6 @@ OptionParser.new do |opts|
78
77
  end
79
78
  opts.on("-tTYPE", "--type TYPE",
80
79
  "Sets the type Canvas lesson to be created (page or assignment). If no type, type decided based on repository structure") do |type|
81
- # byebug
82
80
  options[:type] = type.downcase
83
81
  abort if type == 'quiz' || type == 'discussion'
84
82
  # if type == 'page' || type == 'assignment' || type == 'discussion' || type == 'quiz' || type == 'Page' || type == 'Assignment' || type == 'Discussion' || type == 'Quiz'
@@ -152,10 +150,10 @@ OptionParser.new do |opts|
152
150
  "Use with --map. Outputs repo URLs instead of YAML") do |urls|
153
151
  options[:urls_only] = urls
154
152
  end
155
- # opts.on("--csv COURSE",
156
- # "Returns a course's lesson struction as CSV") do |course|
157
- # options[:csv] = course
158
- # end
153
+ opts.on("--csv",
154
+ "Returns a course's lesson struction as CSV") do |csv|
155
+ options[:csv] = csv
156
+ end
159
157
  opts.on("--read-from-canvas CANVAS_URL",
160
158
  "Retrieves an existing Canvas lesson using the provided URL") do |url|
161
159
  options[:read_from_canvas] = url
@@ -201,9 +199,13 @@ OptionParser.new do |opts|
201
199
  options[:canvas_to_canvas] = canvas_to_canvas
202
200
  end
203
201
  opts.on("--build-from-csv CSV",
204
- "Build a course usin a CSV of lesson repos, names, modules, and types") do |csv_build|
202
+ "Build a course using a CSV of lesson repos, names, modules, and types") do |csv_build|
205
203
  options[:csv_build] = csv_build
206
204
  end
205
+ opts.on("--update-from-csv CSV",
206
+ "Update a course using a CSV of lesson repos, names, modules, types, lesson IDs, and course IDs") do |csv_align|
207
+ options[:csv_align] = csv_align
208
+ end
207
209
 
208
210
 
209
211
  end.parse!
@@ -288,14 +290,15 @@ end
288
290
  if options[:map]
289
291
  GithubToCanvas.new(mode: 'map',
290
292
  file_to_convert: options[:map],
291
- urls_only: !!options[:urls_only])
293
+ urls_only: !!options[:urls_only],
294
+ csv: !!options[:csv])
292
295
  abort
293
296
  end
294
297
 
295
- if options[:csv]
296
- GithubToCanvas.new(mode: 'csv', file_to_convert: options[:csv])
297
- abort
298
- end
298
+ # if options[:csv]
299
+ # GithubToCanvas.new(mode: 'csv', file_to_convert: options[:csv])
300
+ # abort
301
+ # end
299
302
 
300
303
  if options[:csv_build]
301
304
  GithubToCanvas.new(mode: 'csv_build',
@@ -311,6 +314,20 @@ if options[:csv_build]
311
314
  abort
312
315
  end
313
316
 
317
+ if options[:csv_align]
318
+ GithubToCanvas.new(mode: 'csv_align',
319
+ file_to_convert: options[:csv_align],
320
+ course_id: options[:course_id],
321
+ fis_links: !!options[:fis],
322
+ remove_header_and_footer: !!options[:remove_header_and_footer],
323
+ aaq: !!options[:aaq],
324
+ forkable: !!options[:forkable],
325
+ branch: options[:branch],
326
+ contains_html: options[:contains_html],
327
+ git_links: !!options[:git_links])
328
+ abort
329
+ end
330
+
314
331
  if options[:build_course]
315
332
  GithubToCanvas.new(mode: 'build_course',
316
333
  file_to_convert: options[:build_course],
@@ -215,6 +215,47 @@ class GithubToCanvas
215
215
  puts "Creating lesson - #{options[:name]}"
216
216
  response = CanvasInterface.add_to_module(options[:course_id], created_module_info, created_lesson_info)
217
217
 
218
+ }
219
+ when 'csv_align'
220
+
221
+ csv_data = CSV.read(options[:file_to_convert])
222
+ created_module_info = {
223
+ "id" => "",
224
+ "name" => ""
225
+ }
226
+
227
+ csv_data.each { |lesson|
228
+ # lesson[0] == repo
229
+ # lesson[1] == name
230
+ # lesson[2] == module
231
+ # lesson[3] == type
232
+ # lesson[4] == yes/no contains HTML
233
+ # lesson[5] == lesson id
234
+ # lesson[6] == course id
235
+
236
+ module_info = {
237
+ name: lesson[2]
238
+ }
239
+
240
+ options[:filepath] = lesson[0]
241
+ options[:name] = lesson[1]
242
+ options[:type] = lesson[3]
243
+ options[:id] = lesson[5]
244
+ options[:course_id] = lesson[6]
245
+ options[:branch] = "master" if !options[:branch]
246
+ if !options[:contains_html]
247
+ options[:contains_html] = (lesson[4] == "yes" || lesson[4] == "Yes") ? true : false
248
+ end
249
+
250
+
251
+ html = RepositoryConverter.remote_file_conversion(options)
252
+ html = RepositoryConverter.adjust_converted_html(options, html)
253
+ updated_lesson_info = CanvasInterface.update_existing_lesson(options, lesson[1], html)
254
+ updated_lesson_info["page_url"] = updated_lesson_info["url"] if !updated_lesson_info["page_url"]
255
+ updated_lesson_info["id"] = updated_lesson_info["page_url"] if !updated_lesson_info["id"]
256
+ updated_lesson_info["type"] = options[:type]
257
+ puts "Updating lesson - #{options[:name]}"
258
+
218
259
  }
219
260
  else
220
261
  puts VERSION
@@ -1,6 +1,7 @@
1
1
  require 'json'
2
2
  require 'rest-client'
3
3
  require 'yaml'
4
+ require 'byebug'
4
5
  class CanvasInterface
5
6
 
6
7
  def self.create_course(course_info)
@@ -94,14 +95,15 @@ class CanvasInterface
94
95
  if options[:type] == 'page' || options[:type] == 'Page'
95
96
  response = RestClient.get(url, headers)
96
97
  lesson_info = JSON.parse(response)
98
+ lesson_info = lesson_info[0] if lesson_info.kind_of?(Array)
97
99
  url = url.sub(/[^\/]+$/, lesson_info["page_id"].to_s)
98
100
  end
101
+
99
102
  response = RestClient.put(url, payload, headers)
100
103
  rescue
101
104
  puts "Something went wrong while pushing lesson #{options[:id]} to course #{options[:course_id]}"
102
105
  puts "Make sure you are working on lessons that are not locked"
103
106
  abort
104
- ""
105
107
  end
106
108
  JSON.parse(response.body)
107
109
  end
@@ -279,8 +281,9 @@ class CanvasInterface
279
281
  lesson["repository"] = repo
280
282
  else
281
283
  lesson["repository"] = "https://github.com/learn-co-curriculum/" + repo
282
- puts lesson["repository"] if options[:urls_only]
283
284
  end
285
+ puts lesson["repository"] if options[:urls_only]
286
+ puts "#{lesson["repository"]}, #{lesson["title"]}, #{mod[:name]}, #{lesson["type"].downcase}, , #{lesson["id"]}, #{course_info[:id]}" if options[:csv]
284
287
  end
285
288
  sleep(1)
286
289
  lesson
@@ -1,5 +1,5 @@
1
1
  require 'redcarpet'
2
-
2
+ # require 'byebug'
3
3
  class CustomRender < Redcarpet::Render::HTML
4
4
  def block_code(code, lang)
5
5
  "<pre>" \
@@ -14,7 +14,7 @@ end
14
14
 
15
15
  class RepositoryConverter
16
16
  def self.local_file_conversion(options)
17
- GithubInterface.get_updated_repo(options[:filepath], options[:branch])
17
+ # GithubInterface.get_updated_repo(options[:filepath], options[:branch])
18
18
  markdown = RepositoryInterface.read_local_file(options[:filepath], options[:file_to_convert])
19
19
  raw_remote_url = self.set_raw_image_remote_url(options[:filepath])
20
20
  markdown = self.escape_existing_html(markdown) if options[:contains_html]
@@ -46,7 +46,8 @@ class RepositoryConverter
46
46
  renderer = CustomRender.new(escape_html: true, prettify: true, hard_wrap: true)
47
47
  redcarpet = Redcarpet::Markdown.new(CustomRender, options={tables: true, autolink: true, fenced_code_blocks: true, disable_indented_code_blocks: true})
48
48
  html = redcarpet.render(markdown)
49
- # self.remove_line_breaks(html)
49
+ puts "Markdown converted to HTML"
50
+ self.remove_line_breaks(html)
50
51
  end
51
52
 
52
53
  def self.adjust_converted_html(options, html)
@@ -69,12 +70,15 @@ class RepositoryConverter
69
70
  def self.fix_escaped_inline_html_code(html)
70
71
 
71
72
  # stops HTML/JSX code blocks from rendering as HTML in Canvas
72
- html = html.gsub("&amp;gt;</code>", "&gt;</code>")
73
- html = html.gsub("&amp;gt;</code>", "&gt;</code>")
73
+ # html = html.gsub("&amp;gt;</code>", "&gt;</code>")
74
+ # html = html.gsub("&amp;gt;</code>", "&gt;</code>")
74
75
 
75
76
  # fixes < and > code snippets
76
- html = html.gsub("&amp;lt;", "&lt;")
77
- html = html.gsub("&amp;gt;", "&gt;")
77
+
78
+ # html = html.gsub(/<pre><code>(.*?)<\/code><\/pre>/) { |string|
79
+ # byebug
80
+ # }
81
+ # html = html.gsub("&amp;gt;", "&gt;")
78
82
 
79
83
  # # fixes blockquotes
80
84
  # html = html.gsub(/\n<p>&gt\;(.*)\n&gt\;/) { |bq|
@@ -96,9 +100,13 @@ class RepositoryConverter
96
100
 
97
101
 
98
102
  def self.escape_existing_html(markdown)
99
- markdown = markdown.gsub(/<\/(?!iframe)/, "&lt;/")
100
- markdown = markdown.gsub(/<(?!iframe)/, "&lt;")
101
- markdown = markdown.gsub(/(?<!iframe)>/, "&gt;")
103
+ # markdown = markdown.gsub(/<\/(?!iframe)/, "&lt;/")
104
+ # markdown = markdown.gsub(/<(?!iframe)/, "&lt;")
105
+ # markdown = markdown.gsub(/(?<!iframe)>/, "&gt;")
106
+ # byebug
107
+ # markdown = markdown.gsub(/```(.*?)```/) {|s|
108
+ # byebug
109
+ # }
102
110
  end
103
111
 
104
112
  def self.remove_header_and_footer(html)
@@ -154,7 +162,7 @@ class RepositoryConverter
154
162
  remote = GithubInterface.git_remote(filepath)
155
163
  end
156
164
  raw_remote = remote.gsub("git@github.com:","https://raw.githubusercontent.com/")
157
- raw_remote = raw_remote.gsub("https://github.com/","https://raw.githubusercontent.com/")
165
+ raw_remote = raw_remo te.gsub("https://github.com/","https://raw.githubusercontent.com/")
158
166
  raw_remote = raw_remote.gsub(/\/blob\/master\/.*$/,"")
159
167
  raw_remote = raw_remote.gsub(/\/blob\/main\/.*$/,"")
160
168
  raw_remote = raw_remote.gsub(/.git$/,"")
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-to-canvas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton