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 +4 -4
- data/bin/github-to-canvas +9 -2
- data/lib/github-to-canvas.rb +3 -2
- data/lib/github-to-canvas/canvas_interface.rb +35 -19
- data/lib/github-to-canvas/create_canvas_lesson.rb +1 -1
- data/lib/github-to-canvas/repository_converter.rb +2 -2
- data/lib/github-to-canvas/update_canvas_lesson.rb +4 -4
- data/lib/github-to-canvas/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47468e628c6efba04bc04fc9f356e4b8f6866d1fe8bab6cfb5b4cfd7cf3a136e
|
4
|
+
data.tar.gz: 6ea24930762e969677a535bf4e01e227e590eb9770d67819697fdd782ccfc389
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73f226acaf498238218114b38587581dd7f9a2cd15a2f3f5058cb8ad4e2915319315c8d9f1d038ed48c635447e714df66f1ee0e06cb1a812ec3b7a8267d19931
|
7
|
+
data.tar.gz: 1ae3ebf8b2cb9965bfbbb5a34647529d34fc3dc9e87a1e4ecab142c0e577c78dc4425ac4fa554e3a9cad55520c23421164b930316f023dadbc2dce777ad14e47
|
data/bin/github-to-canvas
CHANGED
@@ -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
|
data/lib/github-to-canvas.rb
CHANGED
@@ -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,
|
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
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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,
|
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 = "<
|
79
|
-
thumbs_down_link = "<
|
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,
|
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
|