github-to-canvas 0.1.5 → 0.1.11

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: b18946099c8b4fd23e1c2230f71fac458f932079fd22ada5297732358fec4d0e
4
- data.tar.gz: '092e1b7854f2b4c4026f0713599d423d8eac6431ae16e4f9372c1a00ebb9775c'
3
+ metadata.gz: 25c87f7d039c5d682c061bd089500daa36fbc17944f2b396b7e4e4d09d54d071
4
+ data.tar.gz: f30fae04f6ce01b02b9fb8462eae2bee98504cfcb24a5f56a6642c8cd971d068
5
5
  SHA512:
6
- metadata.gz: d11be9f366fc3a457a671669a57802d6a1a8cc8ff3b0a7e9fa3ee10b4b8b91334cbaa336d39c1e3057c41e787619716d76df3e8523d918393cbb1b6fa9737549
7
- data.tar.gz: 85d91f81000c82d55cb45e02f31c9aa3b2e241c785cb58366f5fbef99b72c7ce76e7e9d70f101cedb7f54c5082b2061926e0453cd8a162227cdba78f96c54e71
6
+ metadata.gz: f04b54f431b6a6c9b786ec8b4542a3a7f488eadf2c3adb632369e3da38522d38bbb7f51d07ebafee759140421bbf932a5e9f834fbe82a094d637f7ba92c5f86a
7
+ data.tar.gz: 7ad2efd5ddb65d660cb3c0d12fb11d14cac39d2b1495e0eb2eb5e7b73ca8c711fc0064b84f3ef2eb0d7bdd09bd547a95b703832edfbacbb454962caabab38585
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'
@@ -108,10 +106,18 @@ OptionParser.new do |opts|
108
106
  "Adds additional Flatiron School HTML after markdown conversion") do |f|
109
107
  options[:fis] = true
110
108
  end
109
+ opts.on("-g", "--git-links",
110
+ "Adds additional GitHub after markdown conversion") do |f|
111
+ options[:git_links] = true
112
+ end
111
113
  opts.on("--aaq",
112
114
  "Adds AAQ flag to HTML header appended with --fis-links") do |aaq|
113
115
  options[:aaq] = aaq
114
116
  end
117
+ opts.on("--prework",
118
+ "Adds prework flag to HTML header appended with --fis-links") do |prework|
119
+ options[:prework] = prework
120
+ end
115
121
  opts.on("--forkable",
116
122
  "Used with --fis-links, adds fork button to HTML header injected into Canvas lesson") do |remote|
117
123
  options[:forkable] = true
@@ -144,10 +150,10 @@ OptionParser.new do |opts|
144
150
  "Use with --map. Outputs repo URLs instead of YAML") do |urls|
145
151
  options[:urls_only] = urls
146
152
  end
147
- # opts.on("--csv COURSE",
148
- # "Returns a course's lesson struction as CSV") do |course|
149
- # options[:csv] = course
150
- # end
153
+ opts.on("--csv",
154
+ "Returns a course's lesson struction as CSV") do |csv|
155
+ options[:csv] = csv
156
+ end
151
157
  opts.on("--read-from-canvas CANVAS_URL",
152
158
  "Retrieves an existing Canvas lesson using the provided URL") do |url|
153
159
  options[:read_from_canvas] = url
@@ -188,6 +194,19 @@ OptionParser.new do |opts|
188
194
  "Escapes all HTML included in source markdown by replacing '<' and '>' with HTML charset values") do |html|
189
195
  options[:contains_html] = html
190
196
  end
197
+ opts.on("--canvas-to-canvas COURSE",
198
+ "Copies an existing Canvas lesson into another Canvas lesson") do |canvas_to_canvas|
199
+ options[:canvas_to_canvas] = canvas_to_canvas
200
+ end
201
+ opts.on("--build-from-csv CSV",
202
+ "Build a course using a CSV of lesson repos, names, modules, and types") do |csv_build|
203
+ options[:csv_build] = csv_build
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
209
+
191
210
 
192
211
  end.parse!
193
212
 
@@ -202,6 +221,16 @@ if options[:read_from_canvas]
202
221
  abort
203
222
  end
204
223
 
224
+ if options[:canvas_to_canvas]
225
+ GithubToCanvas.new(mode: 'canvas_copy',
226
+ filepath: options[:canvas_to_canvas],
227
+ course_id: options[:course_id],
228
+ type: options[:type],
229
+ id: options[:id]
230
+ )
231
+ abort
232
+ end
233
+
205
234
  if options[:read_from_github]
206
235
  GithubToCanvas.new(mode: 'github_read',
207
236
  filepath: options[:read_from_github],
@@ -209,6 +238,7 @@ if options[:read_from_github]
209
238
  forkable: !!options[:forkable],
210
239
  fis_links: !!options[:fis],
211
240
  aaq: !!options[:aaq],
241
+ prework: !!options[:prework],
212
242
  contains_html: options[:contains_html])
213
243
  abort
214
244
  end
@@ -224,6 +254,7 @@ if options[:create_from_github]
224
254
  forkable: !!options[:forkable],
225
255
  fis_links: !!options[:fis],
226
256
  aaq: !!options[:aaq],
257
+ prework: !!options[:prework],
227
258
  contains_html: options[:contains_html])
228
259
  else
229
260
  puts 'Canvas course ID and lesson type required. Example: github-to-canvas --create-from-github URL --course ID --type TYPE'
@@ -243,6 +274,7 @@ if options[:align_from_github]
243
274
  forkable: !!options[:forkable],
244
275
  fis_links: !!options[:fis],
245
276
  aaq: !!options[:aaq],
277
+ prework: !!options[:prework],
246
278
  contains_html: options[:contains_html])
247
279
  else
248
280
  puts 'Canvas course ID, lesson ID, and type required. Example: github-to-canvas --create-from-github URL --course COURSE_ID --id LESSON_ID --type TYPE'
@@ -258,12 +290,41 @@ end
258
290
  if options[:map]
259
291
  GithubToCanvas.new(mode: 'map',
260
292
  file_to_convert: options[:map],
261
- urls_only: !!options[:urls_only])
293
+ urls_only: !!options[:urls_only],
294
+ csv: !!options[:csv])
295
+ abort
296
+ end
297
+
298
+ # if options[:csv]
299
+ # GithubToCanvas.new(mode: 'csv', file_to_convert: options[:csv])
300
+ # abort
301
+ # end
302
+
303
+ if options[:csv_build]
304
+ GithubToCanvas.new(mode: 'csv_build',
305
+ file_to_convert: options[:csv_build],
306
+ course_id: options[:course_id],
307
+ fis_links: !!options[:fis],
308
+ remove_header_and_footer: !!options[:remove_header_and_footer],
309
+ aaq: !!options[:aaq],
310
+ forkable: !!options[:forkable],
311
+ branch: options[:branch],
312
+ contains_html: options[:contains_html],
313
+ git_links: !!options[:git_links])
262
314
  abort
263
315
  end
264
316
 
265
- if options[:csv]
266
- GithubToCanvas.new(mode: 'csv', file_to_convert: options[:csv])
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])
267
328
  abort
268
329
  end
269
330
 
@@ -273,7 +334,10 @@ if options[:build_course]
273
334
  fis_links: !!options[:fis],
274
335
  remove_header_and_footer: !!options[:remove_header_and_footer],
275
336
  aaq: !!options[:aaq],
276
- forkable: !!options[:forkable])
337
+ prework: !!options[:prework],
338
+ forkable: !!options[:forkable],
339
+ contains_html: options[:contains_html],
340
+ git_links: !!options[:git_links])
277
341
  abort
278
342
  end
279
343
 
@@ -286,7 +350,9 @@ if options[:add_to_course]
286
350
  remove_header_and_footer: !!options[:remove_header_and_footer],
287
351
  forkable: !!options[:forkable],
288
352
  aaq: !!options[:aaq],
289
- contains_html: options[:contains_html])
353
+ prework: !!options[:prework],
354
+ contains_html: options[:contains_html],
355
+ git_links: !!options[:git_links])
290
356
  else
291
357
  puts '--course required'
292
358
  end
@@ -300,7 +366,9 @@ if options[:update_course_lessons]
300
366
  remove_header_and_footer: !!options[:remove_header_and_footer],
301
367
  forkable: !!options[:forkable],
302
368
  aaq: !!options[:aaq],
303
- contains_html: options[:contains_html])
369
+ prework: !!options[:prework],
370
+ contains_html: options[:contains_html],
371
+ git_links: !!options[:git_links])
304
372
  abort
305
373
  end
306
374
 
@@ -360,10 +428,12 @@ if options[:create_lesson]
360
428
  type: options[:type],
361
429
  save_to_github: !!options[:save_to_github],
362
430
  fis_links: !!options[:fis],
431
+ git_links: !!options[:git_links],
363
432
  remove_header_and_footer: !!options[:remove_header_and_footer],
364
433
  only_update_content: !!options[:only_content],
365
434
  forkable: !!options[:forkable],
366
435
  aaq: !!options[:aaq],
436
+ prework: !!options[:prework],
367
437
  contains_html: options[:contains_html])
368
438
  end
369
439
 
@@ -377,10 +447,12 @@ if options[:align]
377
447
  name: options[:name],
378
448
  type: options[:type],
379
449
  save_to_github: !!options[:save_to_github],
380
- fis_links: !!options[:fis],
450
+ fis_links: !!options[:fis],
451
+ git_links: !!options[:git_links],
381
452
  remove_header_and_footer: !!options[:remove_header_and_footer],
382
453
  only_update_content: !!options[:only_content],
383
454
  forkable: !!options[:forkable],
384
455
  aaq: !!options[:aaq],
456
+ prework: !!options[:prework],
385
457
  contains_html: options[:contains_html])
386
458
  end
@@ -1,4 +1,4 @@
1
- require 'byebug'
1
+ require 'csv'
2
2
  require_relative './github-to-canvas/create_canvas_lesson'
3
3
  require_relative './github-to-canvas/update_canvas_lesson'
4
4
  require_relative './github-to-canvas/canvas_dotfile'
@@ -26,6 +26,8 @@ class GithubToCanvas
26
26
  CanvasInterface.csv(options[:file_to_convert])
27
27
  when 'canvas_read'
28
28
  puts CanvasInterface.read_lesson(options[:filepath])
29
+ when 'canvas_copy'
30
+ CanvasInterface.copy_lesson(options)
29
31
  when 'github_read'
30
32
  html = RepositoryConverter.remote_file_conversion(options)
31
33
  puts RepositoryConverter.adjust_converted_html(options, html)
@@ -43,16 +45,24 @@ class GithubToCanvas
43
45
  CanvasInterface.update_all_related_lessons(options, name, html)
44
46
 
45
47
  when 'github_create'
48
+ if (!options[:branch])
49
+ options[:branch] = 'master'
50
+ end
46
51
  html = RepositoryConverter.remote_file_conversion(options)
47
- name = options[:name] ? options[:name] : RepositoryInterface.get_name(options[:filepath], html)
48
- html = RepositoryConverter.adjust_converted_html(options, html)
49
52
 
53
+ html = RepositoryConverter.adjust_converted_html(options, html)
54
+ name = options[:name] ? options[:name] : RepositoryInterface.get_name(options[:filepath], html)
55
+ puts name
50
56
  response = CanvasInterface.create_lesson(options, name, html)
51
57
 
52
58
  puts "Canvas lesson created. Lesson available at #{response['html_url']}"
53
59
  when 'github_align'
60
+ if (!options[:branch])
61
+ options[:branch] = 'master'
62
+ end
54
63
  html = RepositoryConverter.remote_file_conversion(options)
55
64
  name = options[:name] ? options[:name] : RepositoryInterface.get_name(options[:filepath], html)
65
+
56
66
  html = RepositoryConverter.adjust_converted_html(options, html)
57
67
  response = CanvasInterface.update_existing_lesson(options, name, html)
58
68
  puts "Canvas lesson updated. Lesson available at #{response['html_url']}"
@@ -152,6 +162,101 @@ class GithubToCanvas
152
162
  end
153
163
  }
154
164
  }
165
+ when 'csv_build'
166
+ if !options[:course_id]
167
+ course_info = {
168
+ name: "CSV Build Test",
169
+ course_code: "CSV-TEST"
170
+ }
171
+ created_course_info = CanvasInterface.create_course(course_info)
172
+ puts "Course created - #{created_course_info["id"]}"
173
+ puts "Make sure to add yourself as a teacher to this course before continuing, then press Enter/Return"
174
+ input = gets
175
+ options[:course_id] = created_course_info["id"]
176
+ else
177
+ puts "Adding to course #{options[:course_id]}"
178
+ end
179
+
180
+ csv_data = CSV.read(options[:file_to_convert])
181
+ created_module_info = {
182
+ "id" => "",
183
+ "name" => ""
184
+ }
185
+
186
+ csv_data.each { |lesson|
187
+ # lesson[0] == repo
188
+ # lesson[1] == name
189
+ # lesson[2] == module
190
+ # lesson[3] == type
191
+ # lesson[4] == yes/no contains HTML
192
+ module_info = {
193
+ name: lesson[2]
194
+ }
195
+ if created_module_info["name"] != module_info[:name]
196
+ created_module_info = CanvasInterface.create_module(options[:course_id], module_info)
197
+ puts "New module created - #{created_module_info["id"]} - #{created_module_info["name"]}"
198
+ end
199
+
200
+ options[:filepath] = lesson[0]
201
+ options[:name] = lesson[1]
202
+ options[:type] = lesson[3]
203
+ options[:branch] = "master" if !options[:branch]
204
+ if !options[:contains_html]
205
+ options[:contains_html] = (lesson[4] == "yes" || lesson[4] == "Yes") ? true : false
206
+ end
207
+
208
+
209
+ html = RepositoryConverter.remote_file_conversion(options)
210
+ html = RepositoryConverter.adjust_converted_html(options, html)
211
+ created_lesson_info = CanvasInterface.create_lesson(options, lesson[1], html)
212
+ created_lesson_info["page_url"] = created_lesson_info["url"] if !created_lesson_info["page_url"]
213
+ created_lesson_info["id"] = created_lesson_info["page_url"] if !created_lesson_info["id"]
214
+ created_lesson_info["type"] = options[:type]
215
+ puts "Creating lesson - #{options[:name]}"
216
+ response = CanvasInterface.add_to_module(options[:course_id], created_module_info, created_lesson_info)
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
+
259
+ }
155
260
  else
156
261
  puts VERSION
157
262
  end
@@ -1,7 +1,7 @@
1
- require 'byebug'
2
1
  require 'json'
3
2
  require 'rest-client'
4
3
  require 'yaml'
4
+ # require 'byebug'
5
5
  class CanvasInterface
6
6
 
7
7
  def self.create_course(course_info)
@@ -51,21 +51,21 @@ class CanvasInterface
51
51
  # POST /api/v1/courses/:course_id/modules/:module_id/items
52
52
  url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/modules/#{module_info["id"]}/items"
53
53
 
54
- if lesson_info["type"] == "Page"
54
+ if lesson_info["type"] == "Page" || lesson_info["type"] == "page"
55
55
  payload = {
56
- 'module_item[title]' => lesson_info["title"],
57
- 'module_item[type]' => lesson_info["type"],
58
- 'module_item[indent]' => 0,
59
- 'module_item[page_url]' => lesson_info["id"],
60
- 'module_item[completion_requirement][type]' => 'must_view'
61
- }
56
+ 'module_item[title]' => lesson_info["title"],
57
+ 'module_item[type]' => lesson_info["type"].capitalize,
58
+ 'module_item[indent]' => 0,
59
+ 'module_item[page_url]' => lesson_info["id"],
60
+ 'module_item[completion_requirement][type]' => 'must_view'
61
+ }
62
62
  elsif lesson_info["type"] == "Quiz"
63
63
  puts "Quiz needs to be added manually - #{lesson_info['title']} - lesson_info["
64
64
  else
65
65
 
66
66
  payload = {
67
67
  'module_item[title]' => lesson_info["title"],
68
- 'module_item[type]' => lesson_info["type"],
68
+ 'module_item[type]' => lesson_info["type"].capitalize,
69
69
  'module_item[indent]' => 1,
70
70
  'module_item[content_id]' => lesson_info["id"],
71
71
  'module_item[completion_requirement][type]' => 'must_submit'
@@ -95,14 +95,16 @@ class CanvasInterface
95
95
  if options[:type] == 'page' || options[:type] == 'Page'
96
96
  response = RestClient.get(url, headers)
97
97
  lesson_info = JSON.parse(response)
98
+ lesson_info = lesson_info[0] if lesson_info.kind_of?(Array)
98
99
  url = url.sub(/[^\/]+$/, lesson_info["page_id"].to_s)
99
100
  end
101
+
100
102
  response = RestClient.put(url, payload, headers)
101
- rescue
103
+ rescue Exception => e
102
104
  puts "Something went wrong while pushing lesson #{options[:id]} to course #{options[:course_id]}"
103
105
  puts "Make sure you are working on lessons that are not locked"
106
+ raise e
104
107
  abort
105
- ""
106
108
  end
107
109
  JSON.parse(response.body)
108
110
  end
@@ -238,7 +240,6 @@ class CanvasInterface
238
240
  puts course_info.to_yaml
239
241
 
240
242
  rescue
241
- byebug
242
243
  puts "Something went wrong while getting info about course #{course}"
243
244
  abort
244
245
  end
@@ -281,8 +282,9 @@ class CanvasInterface
281
282
  lesson["repository"] = repo
282
283
  else
283
284
  lesson["repository"] = "https://github.com/learn-co-curriculum/" + repo
284
- puts lesson["repository"] if options[:urls_only]
285
285
  end
286
+ puts lesson["repository"] if options[:urls_only]
287
+ puts "#{lesson["repository"]}, #{lesson["title"]}, #{mod[:name]}, #{lesson["type"].downcase}, , #{lesson["id"]}, #{course_info[:id]}" if options[:csv]
286
288
  end
287
289
  sleep(1)
288
290
  lesson
@@ -336,12 +338,40 @@ class CanvasInterface
336
338
  end
337
339
  mod
338
340
  end
339
- byebug
340
341
  puts course_info.to_yaml
341
342
  end
342
343
 
343
-
344
+ def self.copy_lesson(options)
345
+ types = ["page", "assignment", "quiz", "discussion"]
346
+ url = options[:filepath]
347
+ type = types.find {|type| url.match(type)}
348
+ options[:type] = type
349
+ if !url.include?(ENV['CANVAS_API_PATH'])
350
+ url = url.sub(/^.*\/\/.*?\//,"#{ENV['CANVAS_API_PATH']}/")
351
+ end
352
+
353
+ response = RestClient.get(url, headers={
354
+ "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
355
+ })
344
356
 
357
+ lesson_info = JSON.parse(response)
358
+ lesson_info = lesson_info.slice("title",
359
+ "name",
360
+ "description",
361
+ "body",
362
+ "message",
363
+ "shuffle_answers",
364
+ "allowed_attempts",
365
+ "question_count"
366
+ )
367
+ if options[:type] == "page"
368
+ self.update_existing_lesson(options, lesson_info["title"], lesson_info["body"])
369
+ else
370
+ self.update_existing_lesson(options, lesson_info["name"], lesson_info["description"])
371
+ end
372
+
373
+
374
+ end
345
375
 
346
376
  def self.build_payload(options, name, html)
347
377
  if options[:only_update_content]
@@ -66,8 +66,7 @@ class GithubInterface
66
66
  puts 'Error reading ' + url
67
67
  end
68
68
  end
69
-
70
-
69
+ response.body
71
70
  end
72
71
 
73
72
  def self.save_to_github(filepath, branch)
@@ -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]
@@ -27,9 +27,15 @@ class RepositoryConverter
27
27
  markdown = GithubInterface.read_remote(options[:filepath])
28
28
  raw_remote_url = self.set_raw_image_remote_url(options[:filepath])
29
29
  if options[:contains_html]
30
- puts "Contains HTML"
31
- puts options[:contains_html]
32
- markdown = self.escape_existing_html(markdown)
30
+ begin
31
+ markdown = self.escape_existing_html(markdown)
32
+ rescue
33
+ puts "Error reading remote markdown"
34
+ abort
35
+ end
36
+ end
37
+ if (!options[:branch])
38
+ options[:branch] = 'master'
33
39
  end
34
40
  markdown = self.fix_local_images(options, markdown, raw_remote_url)
35
41
  html = self.convert_to_html(markdown)
@@ -37,8 +43,10 @@ class RepositoryConverter
37
43
  end
38
44
 
39
45
  def self.convert_to_html(markdown)
40
- redcarpet = Redcarpet::Markdown.new(CustomRender, options={tables: true, autolink: true, fenced_code_blocks: true})
46
+ renderer = CustomRender.new(escape_html: true, prettify: true, hard_wrap: true)
47
+ redcarpet = Redcarpet::Markdown.new(CustomRender, options={tables: true, autolink: true, fenced_code_blocks: true, disable_indented_code_blocks: true})
41
48
  html = redcarpet.render(markdown)
49
+ puts "Markdown converted to HTML"
42
50
  self.remove_line_breaks(html)
43
51
  end
44
52
 
@@ -48,7 +56,7 @@ class RepositoryConverter
48
56
  html = self.remove_header_and_footer(html)
49
57
  end
50
58
 
51
- if options[:fis_links]
59
+ if options[:fis_links] || options[:git_links]
52
60
  html = self.add_fis_links(options, html)
53
61
  end
54
62
 
@@ -60,15 +68,45 @@ class RepositoryConverter
60
68
  end
61
69
 
62
70
  def self.fix_escaped_inline_html_code(html)
63
- html = html.gsub("<code>&amp;lt;", "<code>&lt;")
64
- html = html.gsub("&amp;gt;</code>", "&gt;</code>")
71
+
72
+ # stops HTML/JSX code blocks from rendering as HTML in Canvas
73
+ # html = html.gsub("&amp;gt;</code>", "&gt;</code>")
74
+ # html = html.gsub("&amp;gt;</code>", "&gt;</code>")
75
+
76
+ # fixes < and > code snippets
77
+
78
+ # html = html.gsub(/<pre><code>(.*?)<\/code><\/pre>/) { |string|
79
+ # byebug
80
+ # }
81
+ # html = html.gsub("&amp;gt;", "&gt;")
82
+
83
+ # # fixes blockquotes
84
+ # html = html.gsub(/\n<p>&gt\;(.*)\n&gt\;/) { |bq|
85
+ # bq.delete_prefix!("\n<p>&gt;")
86
+ # "\n<blockquote>" + bq
87
+ # }
88
+ # html = html.gsub(/\n&gt\;(.*)\n&gt\;/) { |bq|
89
+ # bq.delete_prefix!("\n&gt;")
90
+ # " " + bq
91
+ # }
92
+ # html = html.gsub(/\n&gt\;(.*)<\/p>/) { |bq|
93
+ # bq.delete_prefix!("\n&gt\;")
94
+ # bq.delete_suffix!("</p>")
95
+ # " " + bq + "</blockquote>"
96
+ # }
97
+
98
+ html
65
99
  end
66
100
 
67
101
 
68
102
  def self.escape_existing_html(markdown)
69
- markdown = markdown.gsub(/<\/(?!iframe)/, "&lt;/")
70
- markdown = markdown.gsub(/<(?!iframe)/, "&lt;")
71
- 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
+ # }
72
110
  end
73
111
 
74
112
  def self.remove_header_and_footer(html)
@@ -84,6 +122,9 @@ class RepositoryConverter
84
122
 
85
123
  def self.remove_footer(readme)
86
124
  readme.gsub(/<p class='util--hide'(.+?)<\/p>/,"")
125
+ readme.gsub(/<p data-visibility='hidden'(.+?)<\/p>/,"")
126
+ readme.gsub(/<p>&lt\;p data-visibility=&#39\;hidden&#39(.+?)<\/p>/,"")
127
+ readme.gsub(/<p>&lt\;p class=&#39;util--hide&#39\;(.+?)<\/p>/,"")
87
128
  end
88
129
 
89
130
  def self.remove_html_header(html)
@@ -155,7 +196,12 @@ class RepositoryConverter
155
196
  image_source = image_source.gsub(/(\'|\")/, "")
156
197
  image_source = image_source.gsub(/src=/, '')
157
198
  image_source = image_source.strip
158
- 'src="' + raw_remote_url + '/' + branch + '/' + image_source + '"'
199
+
200
+ begin
201
+ 'src="' + raw_remote_url + '/' + branch + '/' + image_source + '"'
202
+ rescue
203
+ puts "Error adjust HTML images - check images in Canvas"
204
+ end
159
205
  else
160
206
  image_source
161
207
  end
@@ -185,12 +231,12 @@ class RepositoryConverter
185
231
  def self.add_fis_links(options, html)
186
232
  repo_info = self.get_repo_info(options[:filepath])
187
233
  html = html.sub(/<div id="git-data-element.*<header class="fis-header.*<\/header>/,'') # remove existing fis header
188
- header = self.create_github_link_header(repo_info[:repo_path], options[:forkable])
189
- data_element = self.create_data_element(repo_info[:repo_org], repo_info[:repo_name], options[:aaq])
234
+ header = self.create_github_link_header(repo_info[:repo_path], options)
235
+ data_element = self.create_data_element(repo_info[:repo_org], repo_info[:repo_name], options[:aaq], options[:prework])
190
236
  data_element + header + html
191
237
  end
192
238
 
193
- def self.create_github_link_header(repo_path, forkable)
239
+ def self.create_github_link_header(repo_path, options)
194
240
  # add link to associated repository
195
241
  github_repo_link = "<a class='fis-git-link' href='#{repo_path}' target='_blank' rel='noopener'><img id='repo-img' title='Open GitHub Repo' alt='GitHub Repo' /></a>"
196
242
 
@@ -198,20 +244,19 @@ class RepositoryConverter
198
244
  github_issue_link = "<a class='fis-git-link' href='#{repo_path}/issues/new' target='_blank' rel='noopener'><img id='issue-img' title='Create New Issue' alt='Create New Issue' /></a>"
199
245
 
200
246
  # add link to fork (forking handled by separate Flatiron server, generation of link handled via custom Canvas JS theme file)
201
- if (forkable)
202
- github_fork_link = "<a class='fis-fork-link' id='fork-link' href='#' target='_blank' rel='noopener'><img id='fork-img' title='Fork This Assignment' alt='Fork This Assignment' /></a>"
247
+
248
+ if (options[:forkable])
249
+ github_fork_link = "<a class='fis-fork-link' id='fork-link' href='#{repo_path}/fork' target='_blank' rel='noopener'><img id='fork-img' title='Fork This Assignment' alt='Fork This Assignment' /></a>"
203
250
  "<header class='fis-header' style='visibility: hidden;'>#{github_fork_link}#{github_repo_link}#{github_issue_link}</header>"
251
+ elsif options[:git_links]
252
+ "<header class='fis-header'>#{github_repo_link}#{github_issue_link}</header>"
204
253
  else
205
254
  "<header class='fis-header' style='visibility: hidden;'>#{github_repo_link}#{github_issue_link}</header>"
206
255
  end
207
256
  end
208
257
 
209
- def self.create_data_element(repo_org, repo_name, aaq)
210
- if (aaq)
211
- "<div id='git-data-element' data-aaq='enabled' data-org='#{repo_org}' data-repo='#{repo_name}'></div>"
212
- else
213
- "<div id='git-data-element' data-org='#{repo_org}' data-repo='#{repo_name}'></div>"
214
- end
258
+ def self.create_data_element(repo_org, repo_name, aaq, prework)
259
+ "<div id='git-data-element' #{prework ? "data-prework='true'" : ""} #{aaq ? "data-aaq='enabled'" : ""} data-org='#{repo_org}' data-repo='#{repo_name}'></div>"
215
260
  end
216
261
 
217
262
 
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.11"
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.5
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.0.8
111
+ rubygems_version: 3.2.3
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: github-to-canvas is a tool for migrating and aligning GitHub content with