github-to-canvas 0.1.7.pre → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53c9c96308fae1d78f27bc68e80fee55baf2ff23d381866edfd1d114b30601ec
4
- data.tar.gz: bf7570a5be4657e102659454295beb72023864ceb20562b51858fa094997b5f7
3
+ metadata.gz: 1ec838f45344a5baa221fdd8269eb9c1405916b8c380b9f6f5d7cd7ca01c3740
4
+ data.tar.gz: d03331e0767f7019ef6cbbb0b0cc7e44209184419ecf09072f96f19bbee3d21d
5
5
  SHA512:
6
- metadata.gz: adbf272b0121b81582d6520bc0c3881980276ede161cb97515d1792563cb29a603c93e7bf35790db1eacc89fb471b68127dccaf24fa43f3205cd758fa53739c2
7
- data.tar.gz: 45182fbe2c428468ed967650a5e42ad496af4fa8dca236b61ec52ef9aa0ace3c209ece9a52eadd46849252a7dd6f9fa7c047a5017057bb96ca5143ee3155784a
6
+ metadata.gz: 906786dea4252483a97dc04c5ecd4684c0ef2800e9a33e3b10a8ac4982912806e4053f18517c6b7577b2206349435f2f8aea61465da27d4c608d13d087a99579
7
+ data.tar.gz: c0482ac88b6f62cc022619a4045ed96392c4834ebc6e4e177e95574d4dbfaec55e8b2f40881d7b9d3d5a04a70678d33203b55886254714843f2a83c121cff0b0
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'
@@ -116,6 +114,10 @@ OptionParser.new do |opts|
116
114
  "Adds AAQ flag to HTML header appended with --fis-links") do |aaq|
117
115
  options[:aaq] = aaq
118
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
119
121
  opts.on("--forkable",
120
122
  "Used with --fis-links, adds fork button to HTML header injected into Canvas lesson") do |remote|
121
123
  options[:forkable] = true
@@ -148,10 +150,10 @@ OptionParser.new do |opts|
148
150
  "Use with --map. Outputs repo URLs instead of YAML") do |urls|
149
151
  options[:urls_only] = urls
150
152
  end
151
- # opts.on("--csv COURSE",
152
- # "Returns a course's lesson struction as CSV") do |course|
153
- # options[:csv] = course
154
- # end
153
+ opts.on("--csv",
154
+ "Returns a course's lesson struction as CSV") do |csv|
155
+ options[:csv] = csv
156
+ end
155
157
  opts.on("--read-from-canvas CANVAS_URL",
156
158
  "Retrieves an existing Canvas lesson using the provided URL") do |url|
157
159
  options[:read_from_canvas] = url
@@ -197,9 +199,13 @@ OptionParser.new do |opts|
197
199
  options[:canvas_to_canvas] = canvas_to_canvas
198
200
  end
199
201
  opts.on("--build-from-csv CSV",
200
- "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|
201
203
  options[:csv_build] = csv_build
202
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
203
209
 
204
210
 
205
211
  end.parse!
@@ -232,6 +238,7 @@ if options[:read_from_github]
232
238
  forkable: !!options[:forkable],
233
239
  fis_links: !!options[:fis],
234
240
  aaq: !!options[:aaq],
241
+ prework: !!options[:prework],
235
242
  contains_html: options[:contains_html])
236
243
  abort
237
244
  end
@@ -247,6 +254,7 @@ if options[:create_from_github]
247
254
  forkable: !!options[:forkable],
248
255
  fis_links: !!options[:fis],
249
256
  aaq: !!options[:aaq],
257
+ prework: !!options[:prework],
250
258
  contains_html: options[:contains_html])
251
259
  else
252
260
  puts 'Canvas course ID and lesson type required. Example: github-to-canvas --create-from-github URL --course ID --type TYPE'
@@ -266,6 +274,7 @@ if options[:align_from_github]
266
274
  forkable: !!options[:forkable],
267
275
  fis_links: !!options[:fis],
268
276
  aaq: !!options[:aaq],
277
+ prework: !!options[:prework],
269
278
  contains_html: options[:contains_html])
270
279
  else
271
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'
@@ -281,14 +290,15 @@ end
281
290
  if options[:map]
282
291
  GithubToCanvas.new(mode: 'map',
283
292
  file_to_convert: options[:map],
284
- urls_only: !!options[:urls_only])
293
+ urls_only: !!options[:urls_only],
294
+ csv: !!options[:csv])
285
295
  abort
286
296
  end
287
297
 
288
- if options[:csv]
289
- GithubToCanvas.new(mode: 'csv', file_to_convert: options[:csv])
290
- abort
291
- end
298
+ # if options[:csv]
299
+ # GithubToCanvas.new(mode: 'csv', file_to_convert: options[:csv])
300
+ # abort
301
+ # end
292
302
 
293
303
  if options[:csv_build]
294
304
  GithubToCanvas.new(mode: 'csv_build',
@@ -304,12 +314,27 @@ if options[:csv_build]
304
314
  abort
305
315
  end
306
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
+
307
331
  if options[:build_course]
308
332
  GithubToCanvas.new(mode: 'build_course',
309
333
  file_to_convert: options[:build_course],
310
334
  fis_links: !!options[:fis],
311
335
  remove_header_and_footer: !!options[:remove_header_and_footer],
312
336
  aaq: !!options[:aaq],
337
+ prework: !!options[:prework],
313
338
  forkable: !!options[:forkable],
314
339
  contains_html: options[:contains_html],
315
340
  git_links: !!options[:git_links])
@@ -325,6 +350,7 @@ if options[:add_to_course]
325
350
  remove_header_and_footer: !!options[:remove_header_and_footer],
326
351
  forkable: !!options[:forkable],
327
352
  aaq: !!options[:aaq],
353
+ prework: !!options[:prework],
328
354
  contains_html: options[:contains_html],
329
355
  git_links: !!options[:git_links])
330
356
  else
@@ -340,6 +366,7 @@ if options[:update_course_lessons]
340
366
  remove_header_and_footer: !!options[:remove_header_and_footer],
341
367
  forkable: !!options[:forkable],
342
368
  aaq: !!options[:aaq],
369
+ prework: !!options[:prework],
343
370
  contains_html: options[:contains_html],
344
371
  git_links: !!options[:git_links])
345
372
  abort
@@ -406,6 +433,7 @@ if options[:create_lesson]
406
433
  only_update_content: !!options[:only_content],
407
434
  forkable: !!options[:forkable],
408
435
  aaq: !!options[:aaq],
436
+ prework: !!options[:prework],
409
437
  contains_html: options[:contains_html])
410
438
  end
411
439
 
@@ -425,5 +453,6 @@ if options[:align]
425
453
  only_update_content: !!options[:only_content],
426
454
  forkable: !!options[:forkable],
427
455
  aaq: !!options[:aaq],
456
+ prework: !!options[:prework],
428
457
  contains_html: options[:contains_html])
429
458
  end
@@ -1,4 +1,3 @@
1
- require 'byebug'
2
1
  require 'csv'
3
2
  require_relative './github-to-canvas/create_canvas_lesson'
4
3
  require_relative './github-to-canvas/update_canvas_lesson'
@@ -53,7 +52,6 @@ class GithubToCanvas
53
52
 
54
53
  html = RepositoryConverter.adjust_converted_html(options, html)
55
54
  name = options[:name] ? options[:name] : RepositoryInterface.get_name(options[:filepath], html)
56
- byebug
57
55
  puts name
58
56
  response = CanvasInterface.create_lesson(options, name, html)
59
57
 
@@ -217,6 +215,47 @@ class GithubToCanvas
217
215
  puts "Creating lesson - #{options[:name]}"
218
216
  response = CanvasInterface.add_to_module(options[:course_id], created_module_info, created_lesson_info)
219
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
+
220
259
  }
221
260
  else
222
261
  puts VERSION
@@ -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)
@@ -74,8 +74,6 @@ class CanvasInterface
74
74
  begin
75
75
  response = RestClient.post(url, payload, self.headers)
76
76
  rescue
77
- byebug
78
-
79
77
  puts "Something went wrong while adding lesson #{lesson_info["id"]} to module #{module_info["id"]} in course #{course_id}" if lesson_info["type"] == "Assignment"
80
78
  puts "Something went wrong while adding lesson #{lesson_info["page_url"]} to module #{module_info["id"]} in course #{course_id}" if lesson_info["type"] == "Page"
81
79
  abort
@@ -97,14 +95,16 @@ class CanvasInterface
97
95
  if options[:type] == 'page' || options[:type] == 'Page'
98
96
  response = RestClient.get(url, headers)
99
97
  lesson_info = JSON.parse(response)
98
+ lesson_info = lesson_info[0] if lesson_info.kind_of?(Array)
100
99
  url = url.sub(/[^\/]+$/, lesson_info["page_id"].to_s)
101
100
  end
101
+
102
102
  response = RestClient.put(url, payload, headers)
103
- rescue
103
+ rescue Exception => e
104
104
  puts "Something went wrong while pushing lesson #{options[:id]} to course #{options[:course_id]}"
105
105
  puts "Make sure you are working on lessons that are not locked"
106
+ raise e
106
107
  abort
107
- ""
108
108
  end
109
109
  JSON.parse(response.body)
110
110
  end
@@ -114,6 +114,8 @@ class CanvasInterface
114
114
  if !options[:id]
115
115
  canvas_data = CanvasDotfile.read_canvas_data
116
116
  response = nil
117
+ puts canvas_data
118
+ puts options
117
119
  canvas_data[:lessons] = canvas_data[:lessons].map { |lesson|
118
120
  response = self.update_existing_lesson(lesson, name, html)
119
121
  options[:id] = lesson[:id]
@@ -240,7 +242,6 @@ class CanvasInterface
240
242
  puts course_info.to_yaml
241
243
 
242
244
  rescue
243
- byebug
244
245
  puts "Something went wrong while getting info about course #{course}"
245
246
  abort
246
247
  end
@@ -283,8 +284,9 @@ class CanvasInterface
283
284
  lesson["repository"] = repo
284
285
  else
285
286
  lesson["repository"] = "https://github.com/learn-co-curriculum/" + repo
286
- puts lesson["repository"] if options[:urls_only]
287
287
  end
288
+ puts lesson["repository"] if options[:urls_only]
289
+ puts "#{lesson["repository"]}, #{lesson["title"]}, #{mod[:name]}, #{lesson["type"].downcase}, , #{lesson["id"]}, #{course_info[:id]}" if options[:csv]
288
290
  end
289
291
  sleep(1)
290
292
  lesson
@@ -338,7 +340,6 @@ class CanvasInterface
338
340
  end
339
341
  mod
340
342
  end
341
- byebug
342
343
  puts course_info.to_yaml
343
344
  end
344
345
 
@@ -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)
@@ -192,7 +200,7 @@ class RepositoryConverter
192
200
  begin
193
201
  'src="' + raw_remote_url + '/' + branch + '/' + image_source + '"'
194
202
  rescue
195
- byebug
203
+ puts "Error adjust HTML images - check images in Canvas"
196
204
  end
197
205
  else
198
206
  image_source
@@ -224,7 +232,7 @@ class RepositoryConverter
224
232
  repo_info = self.get_repo_info(options[:filepath])
225
233
  html = html.sub(/<div id="git-data-element.*<header class="fis-header.*<\/header>/,'') # remove existing fis header
226
234
  header = self.create_github_link_header(repo_info[:repo_path], options)
227
- data_element = self.create_data_element(repo_info[:repo_org], repo_info[:repo_name], options[:aaq])
235
+ data_element = self.create_data_element(repo_info[:repo_org], repo_info[:repo_name], options[:aaq], options[:prework])
228
236
  data_element + header + html
229
237
  end
230
238
 
@@ -247,12 +255,8 @@ class RepositoryConverter
247
255
  end
248
256
  end
249
257
 
250
- def self.create_data_element(repo_org, repo_name, aaq)
251
- if (aaq)
252
- "<div id='git-data-element' data-aaq='enabled' data-org='#{repo_org}' data-repo='#{repo_name}'></div>"
253
- else
254
- "<div id='git-data-element' data-org='#{repo_org}' data-repo='#{repo_name}'></div>"
255
- 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>"
256
260
  end
257
261
 
258
262
 
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.12"
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.7.pre
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton
@@ -104,9 +104,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - ">"
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 1.3.1
109
+ version: '0'
110
110
  requirements: []
111
111
  rubygems_version: 3.2.3
112
112
  signing_key: