github-to-canvas 0.0.23 → 0.0.28

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: a883cc9d8163795840e4d49334c15a3610d7bf95f03ea2791b03ef0311d235d7
4
- data.tar.gz: deb4ee908fe26df4255626f10b6e1ae9dc5a1ffd993e24b8cac399f835eb87ac
3
+ metadata.gz: a2d55d83e956d2f1437ef00fced0e5908ed5e5c4db1b09450a5bc993544a040f
4
+ data.tar.gz: 78a2d3cef6c5814d9bf18b68dd63561e5c79f4d342272229689fc03f411cae44
5
5
  SHA512:
6
- metadata.gz: 1cea54b28ccb0d3e6ffaaf6d271fe5e4317ca92d86abe3958c97c8b1415571e25fed4cddb7317936727575f6696b0d32a3985294d893e7c48851f1ea33b3d210
7
- data.tar.gz: 20af85bf1dc7f8c25a6ff3fb247717d611f6fb74d24716ee96966ec1573fc12516e6223fd4099d0022adbf565ca79b233679976319b4673fb3d4e0a31da59ffb
6
+ metadata.gz: cb37cb15e34de3981106ea56343e310542a3032e9a82eb529e0d3c52d741bf396771cff2e78feeeffce5374a0602141693d673e0187d5d77dbcd0523bc43c55a
7
+ data.tar.gz: 5615ccc3805322be5170f508cfe4726377a12dd2d0e12690b2f7d622ae5cb43b8977f30e7229fd5523ded91645e96b67f91bc8024bcddf605da582c7e0088dca
@@ -19,7 +19,7 @@ OptionParser.new do |opts|
19
19
  github-to-canvas --create COURSE [--branch BRANCH] [--name NAME] [--type TYPE]
20
20
  github-to-canvas --create COURSE [--dry-run]
21
21
  github-to-canvas --create COURSE [--fis-links]
22
- github-to-canvas --create COURSE [--fis-links] [--remove-header]
22
+ github-to-canvas --create COURSE [--fis-links] [--remove-header-and-footer]
23
23
  github-to-canvas --align
24
24
  github-to-canvas --align [--branch BRANCH]
25
25
  github-to-canvas --align [--branch BRANCH] [--fis-links]
@@ -37,7 +37,7 @@ OptionParser.new do |opts|
37
37
  github-to-canvas --create 154 --name "Fetch Lab" --branch solution -> Creates a lesson in course 154 with the provided name, uses the repository's solution branch and derives the type from the local repo
38
38
  github-to-canvas --align -> Patches existing lessons in Canvas based on the .canvas file
39
39
  github-to-canvas --align --fis-links -> Patches existing lessons in Canvas based on the .canvas file, adds addition Flatiron School specific HTML
40
- github-to-canvas --align --remove-header -> Patches existing lessons in Canvas based on the .canvas file, removes top lesson header before converting to HTML
40
+ github-to-canvas --align --remove-header-and-footer -> Patches existing lessons in Canvas based on the .canvas file, removes top lesson header before converting to HTML
41
41
 
42
42
  EOBANNER
43
43
 
@@ -79,9 +79,9 @@ OptionParser.new do |opts|
79
79
  "Adds additional Flatiron School HTML after markdown conversion") do |f|
80
80
  options[:fis] = true
81
81
  end
82
- opts.on("-r", "--remove-header",
83
- "Removes top lesson header before converting to HTML") do |r|
84
- options[:remove_header] = true
82
+ opts.on("-r", "--remove-header-and-footer",
83
+ "Removes top lesson header and any Learn.co specific footer links before converting to HTML") do |r|
84
+ options[:remove_header_and_footer] = true
85
85
  end
86
86
 
87
87
  end.parse!
@@ -115,7 +115,7 @@ if options[:create]
115
115
  type: options[:type],
116
116
  dry: !!options[:dry],
117
117
  fis_links: !!options[:fis],
118
- remove_header: !!options[:remove_header])
118
+ remove_header_and_footer: !!options[:remove_header_and_footer])
119
119
  end
120
120
 
121
121
  if options[:align]
@@ -127,5 +127,5 @@ if options[:align]
127
127
  type: options[:type],
128
128
  dry: !!options[:dry],
129
129
  fis_links: !!options[:fis],
130
- remove_header: !!options[:remove_header])
130
+ remove_header_and_footer: !!options[:remove_header_and_footer])
131
131
  end
@@ -17,7 +17,7 @@ class GithubToCanvas
17
17
  type:"page",
18
18
  dry:false,
19
19
  fis_links:false,
20
- remove_header:false)
20
+ remove_header_and_footer:false)
21
21
 
22
22
  if mode == 'version'
23
23
  puts VERSION
@@ -26,12 +26,12 @@ class GithubToCanvas
26
26
 
27
27
  if mode == 'create'
28
28
  puts "github-to-canvas will now create a Canvas lesson based on the current repo"
29
- CreateCanvasLesson.new(course, filepath, branch, name, type, dry, fis_links, remove_header)
29
+ CreateCanvasLesson.new(course, filepath, branch, name, type, dry, fis_links, remove_header_and_footer)
30
30
  end
31
31
 
32
32
  if mode == 'align'
33
33
  puts "github-to-canvas will now align any existing Canvas lessons based on the current repo. NOTE: .canvas file must be present"
34
- UpdateCanvasLesson.new(filepath, branch, name, type, dry, fis_links, remove_header)
34
+ UpdateCanvasLesson.new(filepath, branch, name, type, dry, fis_links, remove_header_and_footer)
35
35
  end
36
36
  end
37
37
 
@@ -1,16 +1,15 @@
1
1
  require 'yaml'
2
-
3
2
  class CanvasDotfile
4
3
 
5
4
  def self.update_or_create(filepath, response, course, type)
6
5
  if File.file?(".canvas")
7
- if type == "assignment"
6
+ if type == "assignment" || type == "discussion"
8
7
  canvas_data = self.update_assignment_data(response, course, type)
9
8
  else
10
9
  canvas_data = self.update_page_data(response, course, type)
11
10
  end
12
11
  else
13
- if type == "assignment"
12
+ if type == "assignment" || type == "discussion"
14
13
  canvas_data = self.create_assignment_data(response, course, type)
15
14
  else
16
15
  canvas_data = self.create_page_data(response, course, type)
@@ -1,6 +1,5 @@
1
1
  require 'json'
2
2
  require 'rest-client'
3
-
4
3
  class CanvasInterface
5
4
 
6
5
  def self.submit_to_canvas(course_id, type, name, readme, dry_run = false)
@@ -33,7 +32,11 @@ class CanvasInterface
33
32
  end
34
33
 
35
34
  def self.update_existing_lesson(course_id, id, type, name, new_readme, dry_run)
36
- url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s/#{id}"
35
+ if type == "discussion"
36
+ url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}_topics/#{id}"
37
+ else
38
+ url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s/#{id}"
39
+ end
37
40
  payload = self.build_payload(type, name, new_readme)
38
41
  begin
39
42
  RestClient.put(url, payload, headers={
@@ -1,18 +1,18 @@
1
1
  class CreateCanvasLesson
2
2
 
3
- def initialize(course, filepath, branch, name, type, dry_run, fis_links, remove_header)
3
+ def initialize(course, filepath, branch, name, type, dry_run, fis_links, remove_header_and_footer)
4
4
  name = name.split(/[- _]/).map(&:capitalize).join(' ')
5
5
  original_readme = File.read("#{filepath}/README.md")
6
6
  if !original_readme
7
7
  puts 'README.md not found in current directory. Exiting...'
8
8
  abort
9
9
  end
10
- create_canvas_lesson(original_readme, course, filepath, branch, name, type, dry_run, fis_links, remove_header)
10
+ create_canvas_lesson(original_readme, course, filepath, branch, name, type, dry_run, fis_links, remove_header_and_footer)
11
11
  end
12
12
 
13
- def create_canvas_lesson(readme, course, filepath, branch, name, type, dry_run, fis_links, remove_header)
13
+ def create_canvas_lesson(readme, course, filepath, branch, name, type, dry_run, fis_links, remove_header_and_footer)
14
14
  GithubInterface.get_updated_repo(filepath, branch)
15
- new_readme = RepositoryConverter.convert(filepath, readme, branch, remove_header)
15
+ new_readme = RepositoryConverter.convert(filepath, readme, branch, remove_header_and_footer)
16
16
  if fis_links
17
17
  new_readme = RepositoryConverter.add_fis_links(filepath, new_readme)
18
18
  end
@@ -1,4 +1,3 @@
1
- require 'byebug'
2
1
  class GithubInterface
3
2
 
4
3
  def self.cd_into_and(filepath, command)
@@ -1,17 +1,21 @@
1
1
  require 'redcarpet'
2
- require 'byebug'
3
2
  class RepositoryConverter
4
3
 
5
- def self.convert(filepath, readme, branch, remove_header)
6
- if remove_header
7
- self.remove_header(readme)
4
+ def self.convert(filepath, readme, branch, remove_header_and_footer)
5
+ if remove_header_and_footer
6
+ readme = self.remove_header(readme)
7
+ readme = self.remove_footer(readme)
8
8
  end
9
9
  self.fix_local_images(filepath, readme, branch)
10
10
  self.convert_to_html(filepath, readme)
11
11
  end
12
12
 
13
13
  def self.remove_header(readme)
14
- readme.gsub!(/^#.+?\n\n/,"")
14
+ readme.gsub(/^# .+?\n\n/,"")
15
+ end
16
+
17
+ def self.remove_footer(readme)
18
+ readme.gsub(/<p (.+?)<\/p>/,"")
15
19
  end
16
20
 
17
21
  def self.fix_local_images(filepath, readme, branch)
@@ -69,12 +73,14 @@ class RepositoryConverter
69
73
 
70
74
  def self.add_fis_links(filepath, readme)
71
75
  repo = self.get_repo_url(filepath)
72
- github_repo_link = "<a style='text-decoration: none;' href='#{repo}' target='_blank' rel='noopener'><img style='width: 40px; height: 40px; margin: 2px;' title='Open GitHub Repo' src='https://curriculum-content.s3.amazonaws.com/git-logo-gray.png' alt='Link to GitHub Repo' /></a>"
73
- github_issue_link = "<a style='text-decoration: none;' href='#{repo}/issues/new' target='_blank' rel='noopener'><img style='width: 40px; height: 40px; margin: 2px;' title='Create New Issue' src='https://curriculum-content.s3.amazonaws.com/flag-icon-gray.png' alt='Link to GitHub Repo Issue Form' /></a>"
74
-
75
- html = "<p style='margin: 0; padding: 0; position: absolute; right: 5px; top: 5px; margin: 0; padding: 0;'>#{github_repo_link}#{github_issue_link}</p>"
76
-
77
- readme + html
76
+ github_repo_link = "<a class='fis-git-link' href='#{repo}' target='_blank' rel='noopener'><img id='repo-img' title='Open GitHub Repo' alt='GitHub Repo' /></a>"
77
+ github_issue_link = "<a class='fis-git-link' href='#{repo}/issues/new' target='_blank' rel='noopener'><img id='issue-img' title='Create New Issue' alt='Create New Issue' /></a>"
78
+ thumbs_up_link = "<a id='thumbs-up' data-repository='#{repo.split('/')[-1]}'><img title='Thumbs up!' alt='thumbs up' /></a>"
79
+ thumbs_down_link = "<a id='thumbs-down' data-repository='#{repo.split('/')[-1]}'><img title='Thumbs down!' alt='thumbs down' /></a>"
80
+ feedback_link = "<h5>Have specific feedback? <a href='#{repo}/issues/new'>Tell us here!</a></h5>"
81
+ header = "<header class='fis-header' style='visibility: hidden;'>#{github_repo_link}#{github_issue_link}</header>"
82
+ footer = "<footer class='fis-footer' style='visibility: hidden;'><div class='fis-feedback'><h5>How do you feel about this lesson?</h5>#{thumbs_up_link}#{thumbs_down_link}</div>#{feedback_link}</footer>"
83
+ header + readme + footer
78
84
  end
79
85
 
80
86
  end
@@ -1,24 +1,24 @@
1
1
  class UpdateCanvasLesson
2
2
 
3
- def initialize(filepath, branch, name, type, dry_run, fis_links, remove_header)
3
+ def initialize(filepath, branch, name, type, dry_run, fis_links, remove_header_and_footer)
4
4
  name = name.split(/[- _]/).map(&:capitalize).join(' ')
5
5
  readme = File.read("#{filepath}/README.md")
6
6
  if !readme
7
7
  puts 'README.md not found in current directory. Exiting...'
8
8
  abort
9
9
  end
10
- update_canvas_lesson(readme, filepath, branch, name, type, dry_run, fis_links, remove_header)
10
+ update_canvas_lesson(readme, filepath, branch, name, type, dry_run, fis_links, remove_header_and_footer)
11
11
  end
12
12
 
13
- def update_canvas_lesson(readme, filepath, branch, name, type, dry_run, fis_links, remove_header)
13
+ def update_canvas_lesson(readme, filepath, branch, name, type, dry_run, fis_links, remove_header_and_footer)
14
14
  GithubInterface.get_updated_repo(filepath, branch)
15
- new_readme = RepositoryConverter.convert(filepath, readme, branch, remove_header)
15
+ new_readme = RepositoryConverter.convert(filepath, readme, branch, remove_header_and_footer)
16
16
  if fis_links
17
17
  new_readme = RepositoryConverter.add_fis_links(filepath, new_readme)
18
18
  end
19
19
  canvas_data = CanvasDotfile.read_canvas_data
20
20
  canvas_data[:lessons].each { |lesson|
21
- CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], type, name, new_readme, dry_run)
21
+ CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], lesson[:type], name, new_readme, dry_run)
22
22
  }
23
23
  end
24
24
 
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.0.22"
2
+ VERSION = "0.0.28"
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.0.23
4
+ version: 0.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton