github-to-canvas 0.0.34 → 0.0.39

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: a10972429f9c88a53a35e4c1936058ddf4cea1bfbd8dcc28b539c56f137452a6
4
- data.tar.gz: cb101bce0acb8a5089664da90bee2cbea9691152d46b675b797dca625580a019
3
+ metadata.gz: b374fc3c1ba9d2a2260d0e41ae584210e0897c51b8fc54f7286239fbfe810510
4
+ data.tar.gz: 6cbe1e7aa6f31b29f1200191caa1b0c5eb5e93fd255cd9ad68dc9ea18e19132f
5
5
  SHA512:
6
- metadata.gz: 3bd2c769177990932b5429b9b380465864787d62417aa89c9b1b116582c459da313530edfe932b5125bca32b66ac5dc64f8cf0057ba7ef5582c299a3db11fe14
7
- data.tar.gz: fdc82ddd252667def0a2bd26eac727567105ae4389885dec8509a03073b4393a131e547719268ca6fe59803225f58f6e7a4c4173b079a05ce0aaa8058cce0e8e
6
+ metadata.gz: 57ab5ff8e879afda0b4bfbd6bfee46670f650458976b137bc33b38ffe84522bb72e9cef5f7e57d527f58d841833625a0b68040ddb2607d8f21acce1addb7a73f
7
+ data.tar.gz: 363cca9e891442bef50419ff99f4b72f4047b71ea6cc4f28c9914a267587ec4baeb869e9b7d6ac89d595a38b5cb788d7b120a6d37e6131f79345df1b97143e4d
@@ -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
@@ -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.34"
2
+ VERSION = "0.0.39"
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.34
4
+ version: 0.0.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton