github-to-canvas 0.0.35 → 0.0.40

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: f4e34e736ab78c15e73d9b31910e5baaade981a85fad1e4d287ac2bb59cb2636
4
- data.tar.gz: 1e7dd621016ec85200e5a305d9ad87f5bb9d913b553a242de2f4513f33d4e107
3
+ metadata.gz: 47468e628c6efba04bc04fc9f356e4b8f6866d1fe8bab6cfb5b4cfd7cf3a136e
4
+ data.tar.gz: 6ea24930762e969677a535bf4e01e227e590eb9770d67819697fdd782ccfc389
5
5
  SHA512:
6
- metadata.gz: 7a3f26b24d6295a4709c17be3b7c258380e4320f213ffd34e7e84086e08b429cdbcc82a9eacc9c14c36ef91c69bbdbf60087d2081b7c80f22f50235642bfb1ff
7
- data.tar.gz: 021d228fc7c8d8b05b2d2d2e952e9d324f255638b118b86db18a1ca3449a911c86f1b8d32b8fcdd512a78e2c7f8a8b4c7e9b8f8b18b2df4abbbe9f6f82b5e703
6
+ metadata.gz: 73f226acaf498238218114b38587581dd7f9a2cd15a2f3f5058cb8ad4e2915319315c8d9f1d038ed48c635447e714df66f1ee0e06cb1a812ec3b7a8267d19931
7
+ data.tar.gz: 1ae3ebf8b2cb9965bfbbb5a34647529d34fc3dc9e87a1e4ecab142c0e577c78dc4425ac4fa554e3a9cad55520c23421164b930316f023dadbc2dce777ad14e47
@@ -21,6 +21,7 @@ OptionParser.new do |opts|
21
21
  github-to-canvas --create-lesson COURSE [--fis-links] [--remove-header-and-footer]
22
22
  github-to-canvas --align
23
23
  github-to-canvas --align [--branch BRANCH]
24
+ github-to-canvas --align [--only-content]
24
25
  github-to-canvas --align [--branch BRANCH] [--fis-links]
25
26
  github-to-canvas --version
26
27
 
@@ -86,6 +87,10 @@ OptionParser.new do |opts|
86
87
  "Removes top lesson header and any Learn.co specific footer links before converting to HTML") do |r|
87
88
  options[:remove_header_and_footer] = true
88
89
  end
90
+ opts.on("-o", "--only-content",
91
+ "For align functionality only - updates the HTML content of a lesson without changing the name") do |o|
92
+ options[:only_content] = true
93
+ end
89
94
 
90
95
  end.parse!
91
96
 
@@ -128,7 +133,8 @@ if options[:create_lesson]
128
133
  type: options[:type],
129
134
  save_to_github: !!options[:save_to_github],
130
135
  fis_links: !!options[:fis],
131
- remove_header_and_footer: !!options[:remove_header_and_footer])
136
+ remove_header_and_footer: !!options[:remove_header_and_footer],
137
+ only_update_content: !!options[:only_content])
132
138
  end
133
139
 
134
140
  if options[:align]
@@ -141,5 +147,6 @@ if options[:align]
141
147
  type: options[:type],
142
148
  save_to_github: !!options[:save_to_github],
143
149
  fis_links: !!options[:fis],
144
- remove_header_and_footer: !!options[:remove_header_and_footer])
150
+ remove_header_and_footer: !!options[:remove_header_and_footer],
151
+ only_update_content: !!options[:only_content])
145
152
  end
@@ -18,7 +18,8 @@ class GithubToCanvas
18
18
  type:"page",
19
19
  save_to_github:false,
20
20
  fis_links:false,
21
- remove_header_and_footer:false)
21
+ remove_header_and_footer:false,
22
+ only_update_content: false)
22
23
 
23
24
  if mode == 'version'
24
25
  puts VERSION
@@ -32,7 +33,7 @@ class GithubToCanvas
32
33
 
33
34
  if mode == 'align'
34
35
  puts "github-to-canvas will now align any existing Canvas lessons based on the current repo. NOTE: .canvas file must be present"
35
- UpdateCanvasLesson.new(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
36
+ UpdateCanvasLesson.new(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
36
37
  end
37
38
  end
38
39
 
@@ -17,7 +17,7 @@ class CanvasInterface
17
17
  else
18
18
  url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s"
19
19
  end
20
- payload = self.build_payload(type, name, new_readme)
20
+ payload = self.build_payload(type, name, new_readme, false)
21
21
  begin
22
22
  RestClient.post(url, payload, headers={
23
23
  "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
@@ -28,13 +28,13 @@ class CanvasInterface
28
28
  end
29
29
  end
30
30
 
31
- def self.update_existing_lesson(course_id, id, type, name, new_readme, dry_run)
31
+ def self.update_existing_lesson(course_id, id, type, name, new_readme, only_update_content)
32
32
  if type == "discussion"
33
33
  url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}_topics/#{id}"
34
34
  else
35
35
  url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s/#{id}"
36
36
  end
37
- payload = self.build_payload(type, name, new_readme)
37
+ payload = self.build_payload(type, name, new_readme, only_update_content)
38
38
  begin
39
39
  RestClient.put(url, payload, headers={
40
40
  "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
@@ -45,23 +45,39 @@ class CanvasInterface
45
45
  end
46
46
  end
47
47
 
48
- def self.build_payload(type, name, new_readme)
49
- if type == "assignment"
50
- payload = {
51
- 'assignment[name]' => name,
52
- 'assignment[description]' => new_readme
53
- }
54
- elsif type == "discussion"
55
- payload = {
56
- 'title' => name,
57
- 'message' => new_readme
58
- }
48
+ def self.build_payload(type, name, new_readme, only_update_content)
49
+ if only_update_content
50
+ if type == "assignment"
51
+ payload = {
52
+ 'assignment[description]' => new_readme
53
+ }
54
+ elsif type == "discussion"
55
+ payload = {
56
+ 'message' => new_readme
57
+ }
58
+ else
59
+ payload = {
60
+ 'wiki_page[body]' => new_readme
61
+ }
62
+ end
59
63
  else
60
- payload = {
61
- 'wiki_page[title]' => name,
62
- 'wiki_page[body]' => new_readme,
63
- 'wiki_page[editing_roles]' => "teachers"
64
- }
64
+ if type == "assignment"
65
+ payload = {
66
+ 'assignment[name]' => name,
67
+ 'assignment[description]' => new_readme
68
+ }
69
+ elsif type == "discussion"
70
+ payload = {
71
+ 'title' => name,
72
+ 'message' => new_readme
73
+ }
74
+ else
75
+ payload = {
76
+ 'wiki_page[title]' => name,
77
+ 'wiki_page[body]' => new_readme,
78
+ 'wiki_page[editing_roles]' => "teachers"
79
+ }
80
+ end
65
81
  end
66
82
  end
67
83
  end
@@ -8,7 +8,7 @@ class CreateCanvasLesson
8
8
  puts "#{file_to_convert} not found in current directory. Exiting..."
9
9
  abort
10
10
  end
11
- create_canvas_lesson(markdown, course, filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
11
+ create_canvas_lesson(markdown, course, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
12
12
  end
13
13
 
14
14
  def create_canvas_lesson(markdown, course, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
@@ -75,8 +75,8 @@ class RepositoryConverter
75
75
  repo = self.get_repo_url(filepath)
76
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
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>"
78
+ thumbs_up_link = "<img id='thumbs-up' data-repository='#{repo.split('/')[-1]}' title='Thumbs up!' alt='thumbs up' />"
79
+ thumbs_down_link = "<img id='thumbs-down' data-repository='#{repo.split('/')[-1]}' title='Thumbs down!' alt='thumbs down' />"
80
80
  feedback_link = "<h5>Have specific feedback? <a href='#{repo}/issues/new'>Tell us here!</a></h5>"
81
81
  header = "<header class='fis-header' style='visibility: hidden;'>#{github_repo_link}#{github_issue_link}</header>"
82
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>"
@@ -1,6 +1,6 @@
1
1
  class UpdateCanvasLesson
2
2
 
3
- def initialize(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
3
+ def initialize(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
4
4
  name = name.split(/[- _]/).map(&:capitalize).join(' ')
5
5
  begin
6
6
  markdown = File.read("#{filepath}/#{file_to_convert}")
@@ -8,10 +8,10 @@ class UpdateCanvasLesson
8
8
  puts "#{file_to_convert} not found in current directory. Exiting..."
9
9
  abort
10
10
  end
11
- update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
11
+ update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
12
12
  end
13
13
 
14
- def update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
14
+ def update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
15
15
  GithubInterface.get_updated_repo(filepath, branch)
16
16
  new_html = RepositoryConverter.convert(filepath, markdown, branch, remove_header_and_footer)
17
17
  if fis_links
@@ -19,7 +19,7 @@ class UpdateCanvasLesson
19
19
  end
20
20
  canvas_data = CanvasDotfile.read_canvas_data
21
21
  canvas_data[:lessons].each { |lesson|
22
- response = CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], lesson[:type], name, new_html, save_to_github)
22
+ response = CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], lesson[:type], name, new_html, only_update_content)
23
23
  # puts "Canvas lesson created. Lesson available at #{response['html_url']}."
24
24
  }
25
25
  end
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.0.35"
2
+ VERSION = "0.0.40"
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.35
4
+ version: 0.0.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton