github-to-canvas 0.0.32 → 0.0.37

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: a6fe16f342f2f527fb2a604b4028c1f9bcbcbdd6d41221898f5bd35cec4d3065
4
- data.tar.gz: 8946a22cb1c8d962803225eef376859cad05f6e3b84f40d32eaa544a8fa2f27e
3
+ metadata.gz: b5765e93e52076bb10758faf8ceba6b0d6c918f8667e5ccb7020b79e000d6292
4
+ data.tar.gz: d0cea8096a5ec9232073a336e6e7e8d911570f2b96215321281b266eb821ca00
5
5
  SHA512:
6
- metadata.gz: c5129fb84f310b37771de203f27a0686e732f9b8dc4e921321aa00f4934b88e19ccb95c2c649544d90f59ac6b71baa558fad245dcb62c7f16ea182e015dcb55f
7
- data.tar.gz: 0ae0a6ca4da122216a8095c825ec7cee5c2be3b4002a4e9865a639ea17ef8df52a63160c5bdb8ca12ed52b4594e5e27fa76e28dc2658b51494ff5335c5509661
6
+ metadata.gz: ff502c71c949c5b2f84d43bcb28e1dcbecb511f0f39c0201fedfcd367c16a1f7599f8eb4a1a50f15291564b24664e2071ac738752b7216c313db698e69929621
7
+ data.tar.gz: 87461ccffd44eae8dd8006332c1d5a26198a60f104eb58abe972baf27f8fbf1d9418c0e5da368f05963af28ed9f605363c6702a5321c7d7ce36e76c88a71a68d
@@ -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
 
@@ -114,6 +119,10 @@ if !options[:name]
114
119
  end
115
120
  end
116
121
 
122
+ if !options[:file_to_convert]
123
+ options[:file_to_convert] = "README.md"
124
+ end
125
+
117
126
  if options[:create_lesson]
118
127
  GithubToCanvas.new(mode: "create",
119
128
  course: options[:course],
@@ -124,7 +133,8 @@ if options[:create_lesson]
124
133
  type: options[:type],
125
134
  save_to_github: !!options[:save_to_github],
126
135
  fis_links: !!options[:fis],
127
- 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]
128
138
  end
129
139
 
130
140
  if options[:align]
@@ -137,5 +147,6 @@ if options[:align]
137
147
  type: options[:type],
138
148
  save_to_github: !!options[:save_to_github],
139
149
  fis_links: !!options[:fis],
140
- 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]
141
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
@@ -2,12 +2,13 @@ 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
4
  name = name.split(/[- _]/).map(&:capitalize).join(' ')
5
- markdown = File.read("#{filepath}/#{file_to_convert}")
6
- if !markdown
5
+ begin
6
+ markdown = File.read("#{filepath}/#{file_to_convert}")
7
+ rescue
7
8
  puts "#{file_to_convert} not found in current directory. Exiting..."
8
9
  abort
9
10
  end
10
- 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)
11
12
  end
12
13
 
13
14
  def create_canvas_lesson(markdown, course, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
@@ -1,16 +1,17 @@
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
- markdown = File.read("#{filepath}/#{file_to_convert}")
6
- if !markdown
5
+ begin
6
+ markdown = File.read("#{filepath}/#{file_to_convert}")
7
+ rescue
7
8
  puts "#{file_to_convert} not found in current directory. Exiting..."
8
9
  abort
9
10
  end
10
- 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)
11
12
  end
12
13
 
13
- 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)
14
15
  GithubInterface.get_updated_repo(filepath, branch)
15
16
  new_html = RepositoryConverter.convert(filepath, markdown, branch, remove_header_and_footer)
16
17
  if fis_links
@@ -18,8 +19,8 @@ class UpdateCanvasLesson
18
19
  end
19
20
  canvas_data = CanvasDotfile.read_canvas_data
20
21
  canvas_data[:lessons].each { |lesson|
21
- response = CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], lesson[:type], name, new_html, save_to_github)
22
- puts "Canvas lesson created. Lesson available at #{response['html_url']}."
22
+ response = CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], lesson[:type], name, new_html, only_update_content)
23
+ # puts "Canvas lesson created. Lesson available at #{response['html_url']}."
23
24
  }
24
25
  end
25
26
 
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.0.31"
2
+ VERSION = "0.0.37"
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.32
4
+ version: 0.0.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton