github-to-canvas 0.0.44 → 0.0.50

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: 8b61892e1b9cb865805407fb6be99f32272c3b30a3e82b463b265ee08d9f129f
4
- data.tar.gz: 945b3501b5ccd9da9fade3f3e8dc941a3e18e7f643f9478a6eab09c12f199018
3
+ metadata.gz: 5ba8cddad977922a78eb9b92bfac62731ab851e927b906775783a1b18335be82
4
+ data.tar.gz: acbed2faf13bd447c49b1f4c92730bd02f7862e0ac5bf5fe20ae21bc946cea29
5
5
  SHA512:
6
- metadata.gz: 00fb2c6010207bda79a45b1035e76ed4eb7af0452f83bfd827227bd704d908c13431d4cf089e1991ae5a025e273b9feaf32dc9b41664478fb79dfc614b40bf70
7
- data.tar.gz: 93439fa450f1ffbabe96d4a2f44048841d2064cdb0627ba896eb775b35faca653de201a7d284e018f21ea2a1fadc950b71556a5d6ffc6623bded98e115014673
6
+ metadata.gz: 88222800def52566c6d676435a25b144989be96af8fb66968ad5838a851403d063204162a48fc66e1ce57db5a9313a0ad080a40bc5487f775c709bc41ad5d19d
7
+ data.tar.gz: 925a2f22bd80be3003b3b3338114e270cd97997bfbd3f03f0b56b370b6bf95289fc7ef09fd890af2040eac0a0343b2a029abfd937a36e29af9d2ee7dd2bea80c
@@ -36,7 +36,7 @@ OptionParser.new do |opts|
36
36
  github-to-canvas --create-lesson 154 --name "Fetch Lab" --type assignment -> Creates an assignment in course 154 with the provided name
37
37
  github-to-canvas --create-lesson 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
- github-to-canvas --align --fis-links -> Patches existing lessons in Canvas based on the .canvas file, adds addition Flatiron School specific HTML
39
+ github-to-canvas --align --fis-links -> Patches existing lessons in Canvas based on the .canvas file, adds additional Flatiron School specific HTML and meta-data
40
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
  github-to-canvas --info COURSE -> Displays a course's lesson and assignment names
42
42
 
@@ -104,6 +104,10 @@ OptionParser.new do |opts|
104
104
  "Displays a course's lessons and assignments") do |course|
105
105
  options[:query] = course
106
106
  end
107
+ opts.on("--remote",
108
+ "Retrieves a Canvas lesson. Requires --course and --id") do |remote|
109
+ options[:remote] = true
110
+ end
107
111
 
108
112
  end.parse!
109
113
 
@@ -115,6 +119,14 @@ if options[:query]
115
119
  GithubToCanvas.new(mode: 'query', course: options[:query], id: options[:id])
116
120
  end
117
121
 
122
+ if options[:remote]
123
+ if !options[:course] || !options[:id]
124
+ puts "Both --course and --id required when using --remote"
125
+ abort
126
+ end
127
+ GithubToCanvas.new(mode: 'remote', course: options[:course], id: options[:id])
128
+ end
129
+
118
130
  if !options[:type]
119
131
  if Dir.glob("**/*/").empty?
120
132
  options[:type] = "page"
@@ -6,7 +6,6 @@ require_relative './github-to-canvas/canvas_interface'
6
6
  require_relative './github-to-canvas/canvas_dotfile'
7
7
  require_relative './github-to-canvas/version'
8
8
 
9
-
10
9
  class GithubToCanvas
11
10
 
12
11
  def initialize(mode:,
@@ -30,6 +29,18 @@ class GithubToCanvas
30
29
  CanvasInterface.get_course_info(course, id)
31
30
  end
32
31
 
32
+ if mode == 'remote'
33
+ lesson_data = CanvasInterface.get_lesson_info(course, id)
34
+ if !lesson_data[1]
35
+ puts "No lesson with id #{id} was found in course #{course}."
36
+ else
37
+ pp lesson_data[0]
38
+ puts "\nLesson Type: #{lesson_data[1]}"
39
+ end
40
+
41
+
42
+ end
43
+
33
44
  if mode == 'create'
34
45
  puts "github-to-canvas will now create a Canvas lesson based on the current repo"
35
46
  CreateCanvasLesson.new(course, filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
@@ -3,41 +3,41 @@ require 'rest-client'
3
3
  class CanvasInterface
4
4
 
5
5
  def self.get_lesson_info(course, id)
6
- page_url = "#{ENV['CANVAS_API_PATH']}/courses/#{course}/pages/#{id}"
7
- assignment_url = "#{ENV['CANVAS_API_PATH']}/courses/#{course}/assignments/#{id}"
6
+
7
+ lesson_types = ["quizzes", "assignments", "pages", "discussion_topics"]
8
+ lesson_type_urls = []
9
+ lesson_types.each do |type|
10
+ lesson_type_urls << "#{ENV['CANVAS_API_PATH']}/courses/#{course}/#{type}/#{id}"
11
+ end
12
+
8
13
  type = nil
9
14
  info = ""
15
+ lesson_type_urls.each do |url|
10
16
  begin
11
- page_response = RestClient.get(page_url, headers={
17
+ response = RestClient.get(url, headers={
12
18
  "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
13
19
  })
14
- if ([200, 201].include? page_response.code)
15
- info = JSON.parse(page_response.body)
16
- puts "A Canvas page with the ID #{id} was found in course #{course}:"
17
- type = "page"
18
- end
19
- rescue
20
- end
21
-
22
- begin
23
- assignment_response = RestClient.get(assignment_url, headers={
24
- "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
25
- })
26
- if ([200, 201].include? assignment_response.code)
27
- info = JSON.parse(assignment_response.body)
28
- puts "A Canvas assignment with the ID #{id} was found in course #{course}:"
29
- type = "assignment"
20
+ if [200, 201].include? response.code
21
+ info = JSON.parse(response.body)
22
+ type = lesson_types.find {|type| url.match?("#{type}")}
23
+ type.delete_suffix!('zes')
24
+ type.delete_suffix!('s')
25
+ puts "\nA Canvas #{type} was found in course #{course} with the id #{id}"
26
+ break
30
27
  end
31
28
  rescue
32
29
  end
30
+ end
31
+
32
+
33
33
  [info, type]
34
34
  end
35
35
 
36
36
  def self.get_course_info(course, id)
37
37
  if id
38
- info = self.get_lesson_info(course, id)
39
- pp info[1]
40
- pp info[0]
38
+ lesson_data = self.get_lesson_info(course, id)
39
+ pp lesson_data[0]
40
+ pp "\nLesson Type: #{lesson_data[1]}"
41
41
  return
42
42
  end
43
43
 
@@ -1,7 +1,7 @@
1
1
  class CreateCanvasLesson
2
2
 
3
3
  def initialize(course, filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
4
- name = name.split(/[- _]/).map(&:capitalize).join(' ')
4
+ # name = name.split(/[- _]/).map(&:capitalize).join(' ')
5
5
  begin
6
6
  markdown = File.read("#{filepath}/#{file_to_convert}")
7
7
  rescue
@@ -54,9 +54,9 @@ class RepositoryConverter
54
54
  end
55
55
 
56
56
  def self.adjust_local_html_images(readme, raw_remote_url)
57
- readme.gsub!(/src=\"[\s\S]*?"/) { |image_source|
57
+ readme.gsub!(/src=(\'|\")[\s\S]*?(\'|\")/) { |image_source|
58
58
  if !image_source.match?('amazonaws.com') && !image_source.match?('https://') && !image_source.match?('http://') && !image_source.match?('youtube')
59
- image_source.gsub!(/\"/, "")
59
+ image_source.gsub!(/(\'|\")/, "")
60
60
  image_source.gsub!(/src=/, '')
61
61
  image_source.strip!
62
62
  'src="' + raw_remote_url + '/master/' + image_source + '"'
@@ -73,15 +73,24 @@ class RepositoryConverter
73
73
  end
74
74
 
75
75
  def self.add_fis_links(filepath, readme)
76
- repo = self.get_repo_url(filepath)
77
- 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>"
78
- 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>"
79
- thumbs_up_link = "<img id='thumbs-up' data-repository='#{repo.split('/')[-1]}' title='Thumbs up!' alt='thumbs up' />"
80
- thumbs_down_link = "<img id='thumbs-down' data-repository='#{repo.split('/')[-1]}' title='Thumbs down!' alt='thumbs down' />"
81
- feedback_link = "<h5>Have specific feedback? <a href='#{repo}/issues/new'>Tell us here!</a></h5>"
82
- header = "<header class='fis-header' style='visibility: hidden;'>#{github_repo_link}#{github_issue_link}</header>"
83
- 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>"
84
- header + readme + footer
76
+ repo_path = self.get_repo_url(filepath)
77
+ header = self.create_github_link_header(repo_path)
78
+ header + readme
79
+ end
80
+
81
+ def self.create_github_link_header(repo_path)
82
+ repo_name = repo_path.split('/')[-1]
83
+
84
+ # add link to fork (forking handled by separate Flatiron server, generation of link handled via custom Canvas JS theme file)
85
+ github_fork_link = "<a class='fis-fork-link' id='fork-link' data-repo='#{repo_name}' href='#' target='_blank' rel='noopener'><img id='fork-img' title='Fork This Assignment' alt='Fork This Assignment' /></a>"
86
+
87
+ # add link to associated repository
88
+ # 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>"
89
+
90
+ # add link to new issue form
91
+ 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>"
92
+
93
+ "<header class='fis-header' style='visibility: hidden;'>#{github_fork_link}#{github_issue_link}</header>"
85
94
  end
86
95
 
87
96
  end
@@ -1,7 +1,7 @@
1
1
  class UpdateCanvasLesson
2
2
 
3
3
  def initialize(course, filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content, id)
4
- name = name.split(/[- _]/).map(&:capitalize).join(' ')
4
+ # name = name.split(/[- _]/).map(&:capitalize).join(' ')
5
5
  begin
6
6
  markdown = File.read("#{filepath}/#{file_to_convert}")
7
7
  rescue
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.0.44"
2
+ VERSION = "0.0.50"
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.44
4
+ version: 0.0.50
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 3.0.8
109
+ rubygems_version: 3.1.4
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: github-to-canvas is a tool for migrating and aligning GitHub content with