github-to-canvas 0.1.16 → 0.1.17

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: c22dc2963d6dd8ee12c704de58f8a82a636c24abcea448ae49d84f25e8aad3f1
4
- data.tar.gz: b96b71607b765ba283829e0dc5912a5034a9a4e2e1898bb853a36e53e996e0b3
3
+ metadata.gz: 59e47d1d256dca36a7312ef82f6953c5c50df08286a481928233fcdd4dbe0aad
4
+ data.tar.gz: 4d705224c21ac7c70e6c7543a3484baffed2f64c5069c50c070b991079d8011b
5
5
  SHA512:
6
- metadata.gz: bb25c2e7cdcc0c06dd9a63f28b830e0cb7ae3248c0ad4d83f32de4039b9bb169a1a77c18f242b935ac5bf4fd3be950f23114b3354ac6125bed059f0adac17013
7
- data.tar.gz: 62bcc1253d43a08ef2837d45f23eb781a6c80509f50ea5befe3711664e740db58d2770ee1652ca4f503e15b036187d2fd19c1d8884bbf73052edba76d7b4eaf8
6
+ metadata.gz: 03f61185beb39e4fc34421ad7c5a90dc18e7897154fdcfe5da7d7501ae16b13974045e5c4071182f1a02c72b839cfb5688df0a73f0a2f0127ec919f1ef1493b7
7
+ data.tar.gz: 2ad4a5f5d700f377e69ce81c5c26463007faf415ca31aef149b2520e4b843c730e68c052d1467bacedc51a6f9511d94f1a89cd00a94db86081d5f65d803ad967
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source "https://rubygems.org"
2
+
2
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
3
5
  ruby "2.6.1"
4
- gem 'require_all'
5
- gem 'json'
6
- gem 'redcarpet'
7
- gem 'rest-client'
6
+
8
7
  # Specify your gem's dependencies in github-to-canvas.gemspec
8
+ gemspec
data/README.md CHANGED
@@ -25,7 +25,7 @@ also required for some features.
25
25
  In order to access the Canvas API, you must first generate an API key. Go to
26
26
  your Canvas Account Settings and under **Approved Integrations**, create a
27
27
  **New Access Token**. You will need to store this API key as an `ENV` variable
28
- called `CANVAS_API_KEY`.
28
+ called `CANVAS_API_KEY`.
29
29
 
30
30
  If you are using Zsh, the following command will add your new key to the top of `~/.zshrc`:
31
31
 
@@ -74,6 +74,7 @@ The GitHub to Canvas gem can be used for the following:
74
74
  - [Map GitHub Repositories to a Canvas Course YAML file](#map)
75
75
  - [Create New Canvas Course from a YAML file](#buildcourse)
76
76
  - [Update Lessons in an Existing Course from a YAML file](#updatecourse)
77
+ - [Syntax Highlighting](#syntaxhighlighting)
77
78
 
78
79
  ### Creating and Updating Canvas Lessons
79
80
 
@@ -123,7 +124,7 @@ To read the contents of a remote repo:
123
124
  github-to-canvas --read-from-github <URL>
124
125
  ```
125
126
 
126
- This will produce an HTML conversion of the repository's markdwon. This HTML can
127
+ This will produce an HTML conversion of the repository's markdown. This HTML can
127
128
  be directly pasted into Canvas' HTML editor if a manual process is needed.
128
129
 
129
130
  #### Update a Canvas Lesson from a Local Repository <a name="update"></a>
@@ -191,30 +192,30 @@ The output will look similar to this:
191
192
  :name: The Course's Title
192
193
  :id: 111
193
194
  :modules:
194
- - :id: 2020
195
- :name: First Module's Name
196
- :lessons:
197
- - id: slugified-page-name
198
- title: This is the Title Of The First Lesson, a Page
199
- indent: 0
200
- type: Page
201
- html_url: https://learning.flatironschool.com/courses/111/modules/items/27001
202
- page_url: slugified-page-name
203
- url: https://learning.flatironschool.com/api/v1/courses/111/pages/slugified-page-name
204
- published: false
205
- repository: ''
206
- - id: 333
207
- title: This is the Title Of The Second Lesson, an Assignment
208
- indent: 1
209
- type: Assignment
210
- html_url: https://learning.flatironschool.com/courses/111/modules/items/27002
211
- page_url: ''
212
- url: https://learning.flatironschool.com/api/v1/courses/111/assignments/333
213
- published: false
214
- repository: ''
215
- - :id: 2021
216
- :name: Second Module's Name
217
- :lessons:
195
+ - :id: 2020
196
+ :name: First Module's Name
197
+ :lessons:
198
+ - id: slugified-page-name
199
+ title: This is the Title Of The First Lesson, a Page
200
+ indent: 0
201
+ type: Page
202
+ html_url: https://learning.flatironschool.com/courses/111/modules/items/27001
203
+ page_url: slugified-page-name
204
+ url: https://learning.flatironschool.com/api/v1/courses/111/pages/slugified-page-name
205
+ published: false
206
+ repository: ""
207
+ - id: 333
208
+ title: This is the Title Of The Second Lesson, an Assignment
209
+ indent: 1
210
+ type: Assignment
211
+ html_url: https://learning.flatironschool.com/courses/111/modules/items/27002
212
+ page_url: ""
213
+ url: https://learning.flatironschool.com/api/v1/courses/111/assignments/333
214
+ published: false
215
+ repository: ""
216
+ - :id: 2021
217
+ :name: Second Module's Name
218
+ :lessons:
218
219
  ```
219
220
 
220
221
  The output YAML will not include associated GitHub repository information.
@@ -246,7 +247,27 @@ To create a Canvas course with this gem, you will need a correctly structured
246
247
  YAML file with the course info, modules, lessons and associated lesson
247
248
  repositories. In addition, all lessons must have a type (`Page` or
248
249
  `Assignment`), a repository, and a title. Other lesson options are currently
249
- ignored.
250
+ ignored.
251
+
252
+ Here's an example of what the YAML file should look like. Note that for Pages
253
+ the id needs to be present and match the title, based on how Canvas creates
254
+ URL slugs for pages.
255
+
256
+ ```yaml
257
+ ---
258
+ :name: Test Building Course
259
+ :course_code: TEST-GEM-COURSE
260
+ :modules:
261
+ - :name: Module 1
262
+ :lessons:
263
+ - title: Lesson 1
264
+ type: Assignment
265
+ repository: https://github.com/learn-co-curriculum/react-hooks-component-props-mini-project
266
+ - id: lesson-2
267
+ title: Lesson 2
268
+ type: Page
269
+ repository: https://github.com/learn-co-curriculum/phase-0-pac-1-js-variables
270
+ ```
250
271
 
251
272
  With the necessary data configured, use the `--build-course` option and pass in
252
273
  the course's YAML file:
@@ -262,7 +283,7 @@ This command will cause the following to happen:
262
283
  - Create the first lesson using the repository, title and type, as well as additional command options
263
284
  - Add the newly created lesson to the current module
264
285
  - Create the second lesson and add it to the module...
265
- - Repeate process until all modules and lessons are created
286
+ - Repeat process until all modules and lessons are created
266
287
 
267
288
  #### Update Lessons in an Existing Course from a YAML file <a name="updatecourse"></a>
268
289
 
@@ -285,6 +306,23 @@ github-to-canvas --update-course YAML_FILE -lr --forkable
285
306
  The gem will iterate over the data and update every lesson according to the
286
307
  associated repository.
287
308
 
309
+ ## Syntax Highlighting <a name="syntaxhighlighting"></a>
310
+
311
+ This gem uses the [Rouge](https://github.com/rouge-ruby/rouge) Ruby gem to add
312
+ syntax highlighting to
313
+ [fenced code blocks](https://www.markdownguide.org/extended-syntax/#syntax-highlighting).
314
+ Rouge tokenizes the fenced code blocks and generates HTML elements with CSS
315
+ classes to style code blocks. The classes generated by Rouge are intended to
316
+ work with [Pygments](https://pygments.org/).
317
+
318
+ You can download and customize CSS themes for the classes generated by Rouge at this site:
319
+
320
+ - [http://jwarby.github.io/jekyll-pygments-themes/languages/javascript.html](http://jwarby.github.io/jekyll-pygments-themes/languages/javascript.html)
321
+
322
+ After selecting your preferred CSS, you will need to
323
+ [update your Canvas theme](https://community.canvaslms.com/t5/Admin-Guide/How-do-I-upload-custom-JavaScript-and-CSS-files-to-an-account/ta-p/253)
324
+ so the CSS can run on each page.
325
+
288
326
  ## Known Issues
289
327
 
290
328
  ### HTML Code Snippets Do Not Render
@@ -319,18 +357,10 @@ Note that realigning after fixing this content with the gem will break the
319
357
  rendering for these lessons again. A fix is planned for this issue, but has not
320
358
  been implemented.
321
359
 
322
- ### Multi-Line Code Snippets Render as a Single Line
323
-
324
- The Github to Canvas gem uses an existing gem, Redcarpet, to handle the Markdown to HTML
325
- conversion. This gem does not currently support multi-line codeblocks. This
326
- functionality has been added in the Github to Canvas gem through monkeypatching.
327
- This error should be resolved, but if you encounter code snippet rendering
328
- issues, please open a new issue with a markdown example to replicate the error.
329
-
330
360
  ### Markdown Formatting Issues Cause Errors in Canvas
331
361
 
332
362
  An empty line should separate individual markdown headers, paragraphs and code snippets
333
- in the markdown. Without these empty lines, the contents will be interpretted as one
363
+ in the markdown. Without these empty lines, the contents will be interpreted as one
334
364
  continuous paragraph and ignore formatting.
335
365
 
336
366
  ### New Repos That Use a `main` Branch
@@ -404,7 +434,7 @@ Run `github-to-canvas --help` for additional options not listed in this Readme.
404
434
 
405
435
  ## Examples of Valid Images This Gem Can Convert
406
436
 
407
- This gem can convert both standard inline markdown and HTML images.
437
+ This gem can convert both standard inline markdown and HTML images.
408
438
 
409
439
  Inline Markdown:
410
440
 
@@ -416,5 +446,5 @@ HTML:
416
446
  <img src="https://curriculum-content.s3.amazonaws.com/fewpjs/fewpjs-fetch-lab/Image_25_AsynchronousJavaScript.png" width="500">
417
447
  </p>
418
448
 
419
- [Canvas LMS API]: https://canvas.instructure.com/doc/api/index.html
420
- [Flatiron School]: https://flatironschool.com/
449
+ [canvas lms api]: https://canvas.instructure.com/doc/api/index.html
450
+ [flatiron school]: https://flatironschool.com/
data/bin/github-to-canvas CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
4
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
3
5
 
4
6
  require 'optparse'
5
- require 'github-to-canvas'
7
+ require_relative '../lib/github-to-canvas'
6
8
 
7
9
  options = {}
8
10
  OptionParser.new do |opts|
@@ -191,8 +193,8 @@ OptionParser.new do |opts|
191
193
  options[:clone_from_yaml] = file
192
194
  end
193
195
  opts.on("--contains-html",
194
- "Escapes all HTML included in source markdown by replacing '<' and '>' with HTML charset values") do |html|
195
- options[:contains_html] = html
196
+ "DEPRECATED: HTML in code blocks handled by Rouge gem.") do |html|
197
+ puts "--contains-html flag is DEPRECATED: HTML in code blocks handled by Rouge gem."
196
198
  end
197
199
  opts.on("--canvas-to-canvas COURSE",
198
200
  "Copies an existing Canvas lesson into another Canvas lesson") do |canvas_to_canvas|
@@ -238,8 +240,7 @@ if options[:read_from_github]
238
240
  forkable: !!options[:forkable],
239
241
  fis_links: !!options[:fis],
240
242
  aaq: !!options[:aaq],
241
- prework: !!options[:prework],
242
- contains_html: options[:contains_html])
243
+ prework: !!options[:prework])
243
244
  abort
244
245
  end
245
246
 
@@ -254,8 +255,7 @@ if options[:create_from_github]
254
255
  forkable: !!options[:forkable],
255
256
  fis_links: !!options[:fis],
256
257
  aaq: !!options[:aaq],
257
- prework: !!options[:prework],
258
- contains_html: options[:contains_html])
258
+ prework: !!options[:prework])
259
259
  else
260
260
  puts 'Canvas course ID and lesson type required. Example: github-to-canvas --create-from-github URL --course ID --type TYPE'
261
261
  end
@@ -274,8 +274,7 @@ if options[:align_from_github]
274
274
  forkable: !!options[:forkable],
275
275
  fis_links: !!options[:fis],
276
276
  aaq: !!options[:aaq],
277
- prework: !!options[:prework],
278
- contains_html: options[:contains_html])
277
+ prework: !!options[:prework])
279
278
  else
280
279
  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
280
  end
@@ -309,7 +308,6 @@ if options[:csv_build]
309
308
  aaq: !!options[:aaq],
310
309
  forkable: !!options[:forkable],
311
310
  branch: options[:branch],
312
- contains_html: options[:contains_html],
313
311
  git_links: !!options[:git_links])
314
312
  abort
315
313
  end
@@ -323,7 +321,6 @@ if options[:csv_align]
323
321
  aaq: !!options[:aaq],
324
322
  forkable: !!options[:forkable],
325
323
  branch: options[:branch],
326
- contains_html: options[:contains_html],
327
324
  git_links: !!options[:git_links])
328
325
  abort
329
326
  end
@@ -336,7 +333,6 @@ if options[:build_course]
336
333
  aaq: !!options[:aaq],
337
334
  prework: !!options[:prework],
338
335
  forkable: !!options[:forkable],
339
- contains_html: options[:contains_html],
340
336
  git_links: !!options[:git_links])
341
337
  abort
342
338
  end
@@ -351,7 +347,6 @@ if options[:add_to_course]
351
347
  forkable: !!options[:forkable],
352
348
  aaq: !!options[:aaq],
353
349
  prework: !!options[:prework],
354
- contains_html: options[:contains_html],
355
350
  git_links: !!options[:git_links])
356
351
  else
357
352
  puts '--course required'
@@ -367,7 +362,6 @@ if options[:update_course_lessons]
367
362
  forkable: !!options[:forkable],
368
363
  aaq: !!options[:aaq],
369
364
  prework: !!options[:prework],
370
- contains_html: options[:contains_html],
371
365
  git_links: !!options[:git_links])
372
366
  abort
373
367
  end
@@ -433,8 +427,7 @@ if options[:create_lesson]
433
427
  only_update_content: !!options[:only_content],
434
428
  forkable: !!options[:forkable],
435
429
  aaq: !!options[:aaq],
436
- prework: !!options[:prework],
437
- contains_html: options[:contains_html])
430
+ prework: !!options[:prework])
438
431
  end
439
432
 
440
433
  if options[:align]
@@ -453,6 +446,5 @@ if options[:align]
453
446
  only_update_content: !!options[:only_content],
454
447
  forkable: !!options[:forkable],
455
448
  aaq: !!options[:aaq],
456
- prework: !!options[:prework],
457
- contains_html: options[:contains_html])
449
+ prework: !!options[:prework])
458
450
  end
@@ -201,9 +201,6 @@ class GithubToCanvas
201
201
  options[:name] = lesson[1]
202
202
  options[:type] = lesson[3]
203
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
204
 
208
205
 
209
206
  html = RepositoryConverter.remote_file_conversion(options)
@@ -243,9 +240,6 @@ class GithubToCanvas
243
240
  options[:id] = lesson[5]
244
241
  options[:course_id] = lesson[6]
245
242
  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
243
 
250
244
 
251
245
  html = RepositoryConverter.remote_file_conversion(options)
@@ -217,12 +217,9 @@ class CanvasInterface
217
217
  response = RestClient.get(url, self.headers)
218
218
  lessons = JSON.parse(response.body)
219
219
  lessons = lessons.map do |lesson|
220
- if lesson["type"] == "ExternalUrl"
221
- next
222
- end
223
220
  lesson = lesson.slice("id","title","name","indent","type","html_url","page_url","url","completion_requirement", "published")
224
221
  lesson["repository"] = ""
225
- lesson['id'] = lesson['url'].gsub(/^(.*[\\\/])/,'')
222
+ lesson['id'] = lesson['url']&.gsub(/^(.*[\\\/])/,'')
226
223
  lesson
227
224
  end
228
225
  if ([200, 201].include? response.code) && (!lessons.empty?)
@@ -247,6 +244,7 @@ class CanvasInterface
247
244
  course_info = YAML.load(File.read("#{Dir.pwd}/#{options[:file_to_convert]}"))
248
245
  course_info[:modules] = course_info[:modules].map do |mod|
249
246
  mod[:lessons] = mod[:lessons].map do |lesson|
247
+ next lesson unless lesson.key?("url")
250
248
 
251
249
  url = lesson["url"]
252
250
  response = RestClient.get(url, headers={
@@ -1,14 +1,9 @@
1
1
  require 'redcarpet'
2
- class CustomRender < Redcarpet::Render::HTML
3
- def block_code(code, lang)
4
- "<pre>" \
5
- "<code>#{multi_line(code)}</code>" \
6
- "</pre>"
7
- end
2
+ require 'rouge'
3
+ require 'rouge/plugins/redcarpet'
8
4
 
9
- def multi_line(code)
10
- code.gsub(/\n(?=[^.])/, "<br />")
11
- end
5
+ class CustomRender < Redcarpet::Render::HTML
6
+ include Rouge::Plugins::Redcarpet
12
7
  end
13
8
 
14
9
  class RepositoryConverter
@@ -16,7 +11,6 @@ class RepositoryConverter
16
11
  # GithubInterface.get_updated_repo(options[:filepath], options[:branch])
17
12
  markdown = RepositoryInterface.read_local_file(options[:filepath], options[:file_to_convert])
18
13
  raw_remote_url = self.set_raw_image_remote_url(options[:filepath])
19
- markdown = self.escape_existing_html(markdown) if options[:contains_html]
20
14
  markdown = self.fix_local_images(options, markdown, raw_remote_url)
21
15
  html = self.convert_to_html(markdown)
22
16
  # self.fix_local_html_links(options, html, options[:filepath])
@@ -25,14 +19,6 @@ class RepositoryConverter
25
19
  def self.remote_file_conversion(options)
26
20
  markdown = GithubInterface.read_remote(options[:filepath])
27
21
  raw_remote_url = self.set_raw_image_remote_url(options[:filepath])
28
- if options[:contains_html]
29
- begin
30
- markdown = self.escape_existing_html(markdown)
31
- rescue
32
- puts "Error reading remote markdown"
33
- abort
34
- end
35
- end
36
22
  if (!options[:branch])
37
23
  options[:branch] = 'master'
38
24
  end
@@ -42,11 +28,16 @@ class RepositoryConverter
42
28
  end
43
29
 
44
30
  def self.convert_to_html(markdown)
45
- renderer = CustomRender.new(escape_html: true, prettify: true, hard_wrap: true)
46
- redcarpet = Redcarpet::Markdown.new(CustomRender, options={tables: true, autolink: true, fenced_code_blocks: true, disable_indented_code_blocks: true})
31
+ options = {
32
+ tables: true,
33
+ autolink: true,
34
+ fenced_code_blocks: true,
35
+ no_intra_emphasis: true
36
+ }
37
+ redcarpet = Redcarpet::Markdown.new(CustomRender, options)
47
38
  html = redcarpet.render(markdown)
48
39
  puts "Markdown converted to HTML"
49
- self.remove_line_breaks(html)
40
+ html
50
41
  end
51
42
 
52
43
  def self.adjust_converted_html(options, html)
@@ -58,26 +49,9 @@ class RepositoryConverter
58
49
  html = self.add_fis_links(options, html)
59
50
  end
60
51
 
61
- if options[:contains_html]
62
- html = self.fix_escaped_inline_html_code(html)
63
- end
64
52
  html
65
53
  end
66
-
67
- def self.fix_escaped_inline_html_code(html)
68
-
69
- html
70
- end
71
-
72
- def self.escape_existing_html(markdown)
73
- markdown = markdown.gsub(/```(\n|.)*?```/) { |code|
74
- # all code blocks
75
- code = code.gsub("<", "&lt;")
76
- code = code.gsub(">", "&gt;")
77
- }
78
- markdown
79
- end
80
-
54
+
81
55
  def self.remove_header_and_footer(html)
82
56
  new_html = self.remove_html_header(html)
83
57
  # new_html = self.remove_footer(new_html)
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.1.16"
2
+ VERSION = "0.1.17"
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.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton
@@ -11,47 +11,47 @@ cert_chain: []
11
11
  date: 2020-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: faraday
14
+ name: redcarpet
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.15'
19
+ version: '3.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.15'
26
+ version: '3.5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: redcarpet
28
+ name: rest-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.5'
33
+ version: '2.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.5'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rest-client
42
+ name: rouge
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.1'
47
+ version: '3.26'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.1'
54
+ version: '3.26'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -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.2.3
111
+ rubygems_version: 3.0.9
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