github-to-canvas 0.0.24 → 0.0.29

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: d720431e21790c476e0cb901dc357a6c9535df029f9a73739a2d6d7acccb0758
4
- data.tar.gz: a4826c7a1a660e85754f26063a24c277f4991261d460617042e8f14b3df83fb1
3
+ metadata.gz: 277ca5f225d7b666fd529a1914309ce575622645455b0b073bd37a8ab19145cf
4
+ data.tar.gz: 8849918914e4201e73f6a6143e847ce2f30ea6d7bfcb8a6aa48f3adb8c6b88e3
5
5
  SHA512:
6
- metadata.gz: b0cf044ec46931fc2ff748b6e05a57513ab669aed896118a6db61d745b2f7546af8366dc3a33ea92e98c4b3278be62e0dea024a211f23aadf7ff95967c44558a
7
- data.tar.gz: 3b2115286e05dc581c3b953c778e5ab00a4781ca46560666365481cc92bfaa80789080a9002a622a9faed43cd11626e45bdeaaf47406df21adbd81e5552d8b50
6
+ metadata.gz: 04adb2efc3fe4b57e358de6974ecbd0097cd67a26c5a72bbbf1de1bd49dbd48dad44af6828a67c9ab8f0ef97bbe73b58d911be49637c3f24992ecd14bbe20ab8
7
+ data.tar.gz: bdf9b9f2fa0bf3a0bba2b5816d89f3461081f81a5ad92262b0a3a0599f1da21ba1b041f445ca1c13e6766333d2197d90dab17a0481b091345efb68c157c26d3b
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'optparse'
4
4
  require 'github-to-canvas'
5
-
5
+ require 'byebug'
6
6
  options = {}
7
7
  OptionParser.new do |opts|
8
8
  opts.banner = <<-EOBANNER
@@ -13,13 +13,13 @@ OptionParser.new do |opts|
13
13
  https://github.com/learn-co-curriculum/github-to-canvas
14
14
 
15
15
  Commands:
16
- github-to-canvas --create COURSE
17
- github-to-canvas --create COURSE [--branch BRANCH]
18
- github-to-canvas --create COURSE [--branch BRANCH] [--name NAME]
19
- github-to-canvas --create COURSE [--branch BRANCH] [--name NAME] [--type TYPE]
20
- github-to-canvas --create COURSE [--dry-run]
21
- github-to-canvas --create COURSE [--fis-links]
22
- github-to-canvas --create COURSE [--fis-links] [--remove-header]
16
+ github-to-canvas --create-lesson COURSE
17
+ github-to-canvas --create-lesson COURSE [--save]
18
+ github-to-canvas --create-lesson COURSE [--branch BRANCH]
19
+ github-to-canvas --create-lesson COURSE [--branch BRANCH] [--name NAME]
20
+ github-to-canvas --create-lesson COURSE [--branch BRANCH] [--name NAME] [--type TYPE]
21
+ github-to-canvas --create-lesson COURSE [--fis-links]
22
+ github-to-canvas --create-lesson COURSE [--fis-links] [--remove-header-and-footer]
23
23
  github-to-canvas --align
24
24
  github-to-canvas --align [--branch BRANCH]
25
25
  github-to-canvas --align [--branch BRANCH] [--fis-links]
@@ -31,19 +31,19 @@ OptionParser.new do |opts|
31
31
 
32
32
  Example usage:
33
33
 
34
- github-to-canvas --create 154 -> Creates a lesson in course 154, derives the name and type from the local repo
35
- github-to-canvas --create 154 --name "Fetch Lab" -> Creates a lesson in course 154 with the provided name, derives the type from the local repo
36
- github-to-canvas --create 154 --name "Fetch Lab" --type assignment -> Creates an assignment in course 154 with the provided name
37
- github-to-canvas --create 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
34
+ github-to-canvas --create-lesson 154 -> Creates a lesson in course 154, derives the name and type from the local repo
35
+ github-to-canvas --create-lesson 154 --name "Fetch Lab" -> Creates a lesson in course 154 with the provided name, derives the type from the local repo
36
+ github-to-canvas --create-lesson 154 --name "Fetch Lab" --type assignment -> Creates an assignment in course 154 with the provided name
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
39
  github-to-canvas --align --fis-links -> Patches existing lessons in Canvas based on the .canvas file, adds addition Flatiron School specific HTML
40
- github-to-canvas --align --remove-header -> Patches existing lessons in Canvas based on the .canvas file, removes top lesson header before converting to HTML
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
 
42
42
  EOBANNER
43
43
 
44
- opts.on("-cCOURSE", "--create COURSE",
44
+ opts.on("-cCOURSE", "--create-lesson COURSE",
45
45
  "Creates a new canvas lesson, converting the local repository's README.md to HTML. Adds .canvas file to remote repository") do |course|
46
- options[:create] = true
46
+ options[:create_lesson] = true
47
47
  options[:course] = course
48
48
  end
49
49
  opts.on("-bBRANCH", "--branch BRANCH",
@@ -63,6 +63,14 @@ OptionParser.new do |opts|
63
63
  options[:type] = "page"
64
64
  end
65
65
  end
66
+ opts.on("-fFILE", "--file FILE",
67
+ "Looks for and uses a markdown file in the currentt folder as source for conversion. Default file is README.md. Skips writing .canvas to repository") do |file|
68
+ options[:file_to_convert] = file
69
+ end
70
+ opts.on("-s", "--save-to-github",
71
+ "Creates a local .canvas file and attempts to commit and push it to the GitHub repository") do |s|
72
+ options[:save_to_github] = true
73
+ end
66
74
  opts.on("-a", "--align",
67
75
  "Updates a canvas lesson based on the local repository's README.md") do |a|
68
76
  options[:align] = true
@@ -71,17 +79,13 @@ OptionParser.new do |opts|
71
79
  "Displays current gem version") do |v|
72
80
  options[:version] = true
73
81
  end
74
- opts.on("-d", "--dry-run",
75
- "Runs through creation without pushing to Canvas or GitHub") do |d|
76
- options[:dry] = true
77
- end
78
- opts.on("-f", "--fis-links",
82
+ opts.on("-l", "--fis-links",
79
83
  "Adds additional Flatiron School HTML after markdown conversion") do |f|
80
84
  options[:fis] = true
81
85
  end
82
- opts.on("-r", "--remove-header",
83
- "Removes top lesson header before converting to HTML") do |r|
84
- options[:remove_header] = true
86
+ opts.on("-r", "--remove-header-and-footer",
87
+ "Removes top lesson header and any Learn.co specific footer links before converting to HTML") do |r|
88
+ options[:remove_header_and_footer] = true
85
89
  end
86
90
 
87
91
  end.parse!
@@ -90,6 +94,10 @@ if options[:version]
90
94
  GithubToCanvas.new(mode: 'version', course: nil)
91
95
  end
92
96
 
97
+ if !options[:file_to_convert]
98
+ options[:file_to_convert] = "README.md"
99
+ end
100
+
93
101
  if !options[:type]
94
102
  if Dir.glob("**/*/").empty?
95
103
  options[:type] = "page"
@@ -106,26 +114,30 @@ if !options[:name]
106
114
  options[:name] = File.basename(Dir.getwd)
107
115
  end
108
116
 
109
- if options[:create]
117
+ byebug
118
+
119
+ if options[:create_lesson]
110
120
  GithubToCanvas.new(mode: "create",
111
121
  course: options[:course],
112
122
  filepath: Dir.pwd,
123
+ file_to_convert: options[:file_to_convert],
113
124
  branch: options[:branch],
114
125
  name: options[:name],
115
126
  type: options[:type],
116
- dry: !!options[:dry],
127
+ save_to_github: !!options[:save_to_github],
117
128
  fis_links: !!options[:fis],
118
- remove_header: !!options[:remove_header])
129
+ remove_header_and_footer: !!options[:remove_header_and_footer])
119
130
  end
120
131
 
121
132
  if options[:align]
122
133
  GithubToCanvas.new(mode: "align",
123
134
  course: nil,
124
- filepath: Dir.pwd,
135
+ filepath: Dir.pwd,
136
+ file_to_convert: options[:file_to_convert],
125
137
  branch: options[:branch],
126
138
  name: options[:name],
127
139
  type: options[:type],
128
- dry: !!options[:dry],
140
+ save_to_github: !!options[:save_to_github],
129
141
  fis_links: !!options[:fis],
130
- remove_header: !!options[:remove_header])
142
+ remove_header_and_footer: !!options[:remove_header_and_footer])
131
143
  end
@@ -12,12 +12,13 @@ class GithubToCanvas
12
12
  def initialize(mode:,
13
13
  course:,
14
14
  filepath:Dir.pwd,
15
- branch:'master',
15
+ file_to_convert:'README.md',
16
+ branch:'master',
16
17
  name:File.basename(Dir.getwd),
17
18
  type:"page",
18
- dry:false,
19
+ save_to_github:false,
19
20
  fis_links:false,
20
- remove_header:false)
21
+ remove_header_and_footer:false)
21
22
 
22
23
  if mode == 'version'
23
24
  puts VERSION
@@ -26,12 +27,12 @@ class GithubToCanvas
26
27
 
27
28
  if mode == 'create'
28
29
  puts "github-to-canvas will now create a Canvas lesson based on the current repo"
29
- CreateCanvasLesson.new(course, filepath, branch, name, type, dry, fis_links, remove_header)
30
+ CreateCanvasLesson.new(course, filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
30
31
  end
31
32
 
32
33
  if mode == 'align'
33
34
  puts "github-to-canvas will now align any existing Canvas lessons based on the current repo. NOTE: .canvas file must be present"
34
- UpdateCanvasLesson.new(filepath, branch, name, type, dry, fis_links, remove_header)
35
+ UpdateCanvasLesson.new(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
35
36
  end
36
37
  end
37
38
 
@@ -1,16 +1,15 @@
1
1
  require 'yaml'
2
-
3
2
  class CanvasDotfile
4
3
 
5
4
  def self.update_or_create(filepath, response, course, type)
6
5
  if File.file?(".canvas")
7
- if type == "assignment"
6
+ if type == "assignment" || type == "discussion"
8
7
  canvas_data = self.update_assignment_data(response, course, type)
9
8
  else
10
9
  canvas_data = self.update_page_data(response, course, type)
11
10
  end
12
11
  else
13
- if type == "assignment"
12
+ if type == "assignment" || type == "discussion"
14
13
  canvas_data = self.create_assignment_data(response, course, type)
15
14
  else
16
15
  canvas_data = self.create_page_data(response, course, type)
@@ -1,19 +1,14 @@
1
1
  require 'json'
2
2
  require 'rest-client'
3
-
4
3
  class CanvasInterface
5
4
 
6
- def self.submit_to_canvas(course_id, type, name, readme, dry_run = false)
7
- if dry_run
8
- puts 'DRY RUN: Skipping push to Canvas'
9
- else
10
- response = self.push_to_canvas(course_id, type, name, readme)
11
- if ![200, 201].include? response.code
12
- puts "Canvas push failed. #{response.code} status code returned "
13
- abort
14
- end
15
- JSON.parse(response.body)
5
+ def self.submit_to_canvas(course_id, type, name, readme)
6
+ response = self.push_to_canvas(course_id, type, name, readme)
7
+ if ![200, 201].include? response.code
8
+ puts "Canvas push failed. #{response.code} status code returned "
9
+ abort
16
10
  end
11
+ JSON.parse(response.body)
17
12
  end
18
13
 
19
14
  def self.push_to_canvas(course_id, type, name, new_readme)
@@ -29,11 +24,16 @@ class CanvasInterface
29
24
  })
30
25
  rescue
31
26
  puts "Something went wrong while pushing lesson #{id} to course #{course_id}"
27
+ abort
32
28
  end
33
29
  end
34
30
 
35
31
  def self.update_existing_lesson(course_id, id, type, name, new_readme, dry_run)
36
- url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s/#{id}"
32
+ if type == "discussion"
33
+ url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}_topics/#{id}"
34
+ else
35
+ url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s/#{id}"
36
+ end
37
37
  payload = self.build_payload(type, name, new_readme)
38
38
  begin
39
39
  RestClient.put(url, payload, headers={
@@ -41,6 +41,7 @@ class CanvasInterface
41
41
  })
42
42
  rescue
43
43
  puts "Something went wrong while pushing lesson #{id} to course #{course_id}"
44
+ # abort
44
45
  end
45
46
  end
46
47
 
@@ -1,29 +1,31 @@
1
1
  class CreateCanvasLesson
2
2
 
3
- def initialize(course, filepath, branch, name, type, dry_run, fis_links, remove_header)
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
- original_readme = File.read("#{filepath}/README.md")
6
- if !original_readme
7
- puts 'README.md not found in current directory. Exiting...'
5
+ markdown = File.read("#{filepath}/#{file_to_convert}")
6
+ if !markdown
7
+ puts "#{file_to_convert} not found in current directory. Exiting..."
8
8
  abort
9
9
  end
10
- create_canvas_lesson(original_readme, course, filepath, branch, name, type, dry_run, fis_links, remove_header)
10
+ create_canvas_lesson(markdown, course, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
11
11
  end
12
12
 
13
- def create_canvas_lesson(readme, course, filepath, branch, name, type, dry_run, fis_links, remove_header)
13
+ def create_canvas_lesson(markdown, course, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
14
14
  GithubInterface.get_updated_repo(filepath, branch)
15
- new_readme = RepositoryConverter.convert(filepath, readme, branch, remove_header)
15
+ new_html = RepositoryConverter.convert(filepath, markdown, branch, remove_header_and_footer)
16
16
  if fis_links
17
- new_readme = RepositoryConverter.add_fis_links(filepath, new_readme)
17
+ new_html = RepositoryConverter.add_fis_links(filepath, new_html)
18
18
  end
19
- response = CanvasInterface.submit_to_canvas(course, type, name, new_readme, dry_run)
20
- if dry_run
21
- puts 'DRY RUN: Skipping dotfile creation and push to GitHub'
22
- else
19
+ response = CanvasInterface.submit_to_canvas(course, type, name, new_html)
20
+ if save_to_github
21
+ puts 'Creating .canvas file'
23
22
  CanvasDotfile.update_or_create(filepath, response, course, type)
23
+ puts 'Commiting .canvas file'
24
24
  CanvasDotfile.commit_canvas_dotfile(filepath)
25
+ puts 'Pushing .canvas file'
25
26
  GithubInterface.git_push(filepath, branch)
26
27
  end
28
+ puts "Canvas lesson created. Lesson available at #{response['html_url']}."
27
29
  end
28
30
 
29
31
  end
@@ -1,4 +1,3 @@
1
- require 'byebug'
2
1
  class GithubInterface
3
2
 
4
3
  def self.cd_into_and(filepath, command)
@@ -1,17 +1,21 @@
1
1
  require 'redcarpet'
2
- require 'byebug'
3
2
  class RepositoryConverter
4
3
 
5
- def self.convert(filepath, readme, branch, remove_header)
6
- if remove_header
7
- self.remove_header(readme)
4
+ def self.convert(filepath, readme, branch, remove_header_and_footer)
5
+ if remove_header_and_footer
6
+ readme = self.remove_header(readme)
7
+ readme = self.remove_footer(readme)
8
8
  end
9
9
  self.fix_local_images(filepath, readme, branch)
10
10
  self.convert_to_html(filepath, readme)
11
11
  end
12
12
 
13
13
  def self.remove_header(readme)
14
- readme.gsub!(/^#.+?\n\n/,"")
14
+ readme.gsub(/^# .+?\n\n/,"")
15
+ end
16
+
17
+ def self.remove_footer(readme)
18
+ readme.gsub(/<p (.+?)<\/p>/,"")
15
19
  end
16
20
 
17
21
  def self.fix_local_images(filepath, readme, branch)
@@ -69,12 +73,14 @@ class RepositoryConverter
69
73
 
70
74
  def self.add_fis_links(filepath, readme)
71
75
  repo = self.get_repo_url(filepath)
72
- github_repo_link = "<a style='text-decoration: none;' href='#{repo}' target='_blank' rel='noopener'><img style='width: 40px; height: 40px; margin: 2px;' title='Open GitHub Repo' src='https://curriculum-content.s3.amazonaws.com/git-logo-gray.png' alt='Link to GitHub Repo' /></a>"
73
- github_issue_link = "<a style='text-decoration: none;' href='#{repo}/issues/new' target='_blank' rel='noopener'><img style='width: 40px; height: 40px; margin: 2px;' title='Create New Issue' src='https://curriculum-content.s3.amazonaws.com/flag-icon-gray.png' alt='Link to GitHub Repo Issue Form' /></a>"
74
-
75
- html = "<p style='margin: 0; padding: 0; position: absolute; right: 5px; top: 5px; margin: 0; padding: 0;'>#{github_repo_link}#{github_issue_link}</p>"
76
-
77
- readme + html
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
+ 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>"
80
+ feedback_link = "<h5>Have specific feedback? <a href='#{repo}/issues/new'>Tell us here!</a></h5>"
81
+ header = "<header class='fis-header' style='visibility: hidden;'>#{github_repo_link}#{github_issue_link}</header>"
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>"
83
+ header + readme + footer
78
84
  end
79
85
 
80
86
  end
@@ -1,24 +1,25 @@
1
1
  class UpdateCanvasLesson
2
2
 
3
- def initialize(filepath, branch, name, type, dry_run, fis_links, remove_header)
3
+ def initialize(filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
4
4
  name = name.split(/[- _]/).map(&:capitalize).join(' ')
5
- readme = File.read("#{filepath}/README.md")
6
- if !readme
7
- puts 'README.md not found in current directory. Exiting...'
5
+ markdown = File.read("#{filepath}/#{file_to_convert}")
6
+ if !markdown
7
+ puts "#{file_to_convert} not found in current directory. Exiting..."
8
8
  abort
9
9
  end
10
- update_canvas_lesson(readme, filepath, branch, name, type, dry_run, fis_links, remove_header)
10
+ update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
11
11
  end
12
12
 
13
- def update_canvas_lesson(readme, filepath, branch, name, type, dry_run, fis_links, remove_header)
13
+ def update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
14
14
  GithubInterface.get_updated_repo(filepath, branch)
15
- new_readme = RepositoryConverter.convert(filepath, readme, branch, remove_header)
15
+ new_html = RepositoryConverter.convert(filepath, markdown, branch, remove_header_and_footer)
16
16
  if fis_links
17
- new_readme = RepositoryConverter.add_fis_links(filepath, new_readme)
17
+ new_html = RepositoryConverter.add_fis_links(filepath, new_html) # adds Flatiron School specific header and footer
18
18
  end
19
19
  canvas_data = CanvasDotfile.read_canvas_data
20
20
  canvas_data[:lessons].each { |lesson|
21
- CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], type, name, new_readme, dry_run)
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
23
  }
23
24
  end
24
25
 
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.0.24"
2
+ VERSION = "0.0.29"
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.24
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton