github-to-canvas 0.0.56 → 0.1.2

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: 35b2320509da12ac07b0a2905c4302b8a2d3d492f2fc04bcd5dc606b8fb36cb3
4
- data.tar.gz: 7964bd362c1315ddf7203f6f9599e8a69469d59579457fb6dd632c80c0127be5
3
+ metadata.gz: f5628681c8cda313989c521770b0b7f2a20e9b7a0aa0f661446d25d1040eca8d
4
+ data.tar.gz: da78038dd5492dbb897c9fb6d65e05c76f02e7e57df952630c859d9b446d6c79
5
5
  SHA512:
6
- metadata.gz: c55a64f4a56fcb795af943a9db7e9799164cd19c5119738c0899ce3b73e1b8998a5c16ce676d5553828bf6d0f54b55d804c2066c2702e113ace009649e0ece3d
7
- data.tar.gz: 37e1f2a57675d8ec0cb9dc6e36716b35b7ca8ab38b243e4cb6186a17fe0894c4b1ef8fde65dc0fbdaf3bb242d0bafcd08dd243abbb83acf03139de75597f95a4
6
+ metadata.gz: abc12344a24c0c7d67980dc4911462e7c7eb3aba0c31e18b42e5f95fda97fef7b60a994c4ce59fc6da3d6fb7db044fc47ae443979e06455a82906e4ae863f4cd
7
+ data.tar.gz: 467e1d799b929fccf52cb155d27411050232c30b704fde8d216516c1bc7891d69c6617252cfdd8782ceb35a10fd05b2d5efdf5dd6754bfb097f22ee740876f36
data/README.md CHANGED
@@ -4,19 +4,15 @@
4
4
 
5
5
  The `github-to-canvas` gem is designed to aid in integrating GitHub and the
6
6
  Canvas LMS. This gem takes a GitHub repository's `README.md` file, converts it
7
- to HTML, and pushes it to Canvas using the Canvas API. The gem also has the ability
8
- to updates a repository to include a `.canvas` file containing Canvas specific
9
- information.
10
-
11
- With the `.canvas` file in place, this gem can be used to continuously align
12
- content between GitHub and Canvas using the GitHub repository as the single
13
- source of truth.
7
+ to HTML, and pushes it to Canvas using the Canvas API. This gem can also update
8
+ existing Canvas lessons, allowing continuous alignment of content between GitHub
9
+ and Canvas.
14
10
 
15
11
  This gem is built for use internally at [Flatiron School][], so some features may be
16
12
  specific to Flatiron School branding and needs. Access to the
17
13
  [Canvas LMS API][] and the ability to add pages and assignments to a Canvas
18
14
  course are required. Write access to the GitHub repository being converted is
19
- also required for committing `.canvas` files.
15
+ also required for some features.
20
16
 
21
17
  ## Installation
22
18
 
@@ -47,7 +43,7 @@ echo "$(export 'CANVAS_API_KEY=your-new-API-key-here' | cat - ~/.bash_profile)"
47
43
 
48
44
  ### Add Canvas API Base Path
49
45
 
50
- The exact Canvas API path is specific to where you Canvas LMS is located. For example,
46
+ The exact Canvas API path is specific to where your Canvas LMS is located. For example,
51
47
  Flatiron School's base path is `https://learning.flatironschool.com/api/v1`. Add this path
52
48
  as an `ENV` variable like the API key. **Do not add a `/` at the end after `/api/v1`.**
53
49
 
@@ -65,67 +61,350 @@ After both the API key and path are added to `~/.zshrc`, run `source ~/.zshrc` (
65
61
  to make them available in your current terminal. You can verify these variables
66
62
  are present by running `ENV` and finding them in the output list.
67
63
 
68
- ## Usage
64
+ ## Common Uses
65
+
66
+ The GitHub to Canvas gem can be used for the following:
67
+
68
+ - [Create a Canvas Lesson from a Local Repository](#create)
69
+ - [Create a Canvas Lesson from a Remote Repository](#createremote)
70
+ - [Read a Remote Repository as HTML](#read)
71
+ - [Update a Canvas Lesson from a Local Repository](#update)
72
+ - [Update a Canvas Lesson from a Remote Repository](#updateremote)
73
+ - [Retrieve Canvas Course Information as YAML Markdown](#query)
74
+ - [Map GitHub Repositories to a Canvas Course YAML file](#map)
75
+ - [Create New Canvas Course from a YAML file](#buildcourse)
76
+ - [Update Lessons in an Existing Course from a YAML file](#updatecourse)
77
+
78
+ ### Creating and Updating Canvas Lessons
79
+
80
+ #### Create a Canvas Lesson from a Local Repository <a name="create"></a>
81
+
82
+ Navigate into a repository folder cloned down to your local machine and run:
83
+
84
+ ```sh
85
+ github-to-canvas -c <CANVAS_COURSE_ID> -lr --forkable
86
+ ```
87
+
88
+ The command above will create a Canvas lesson in the course provided. It will
89
+ also remove the repositories top-level header and remove any old Flatiron
90
+ branded footers. It will also add an HTML header for Canvas that includes links
91
+ back to the repository.
92
+
93
+ If the lesson type is an assignment, a Fork button will also be added to the
94
+ HTML header. Because the command didn't specify, the type of lesson is determined
95
+ based on the local repo structure - if it has sub-folders, the lesson will become
96
+ an assignment; if there are no sub-folders, the lesson will become a page. If the
97
+ lesson type is a page, the `--forkable` option will be ignored.
98
+
99
+ Creating a lesson this way will also produce a `.canvas` file. This file
100
+ contains info about the Canvas lesson that was created.
101
+
102
+ #### Create a Canvas Lesson from a Remote Repository <a name="createremote"></a>
103
+
104
+ To create from a remote repo, run the following command:
105
+
106
+ ```sh
107
+ github-to-canvas --create-from-github <URL> --course <CANVAS_COURSE_ID> --type <TYPE> -lr --forkable
108
+ ```
109
+
110
+ This command will read a GitHub markdown based on the provided URL and create a
111
+ Canvas lesson based on it. We need to provide the Course ID and the type of
112
+ lesson (`page` or `assignment`) as type can't be determined automatically. We'll
113
+ also continue to use `-lr --forkable` like the previous command to set up the
114
+ lesson the same way as before.
115
+
116
+ The repository must be public in order to read the markdown file.
117
+
118
+ #### Read a Remote Repository as HTML <a name="read"></a>
119
+
120
+ To read the contents of a remote repo:
121
+
122
+ ```sh
123
+ github-to-canvas --read-from-github <URL>
124
+ ```
125
+
126
+ This will produce an HTML conversion of the repository's markdwon. This HTML can
127
+ be directly pasted into Canvas' HTML editor if a manual process is needed.
128
+
129
+ #### Update a Canvas Lesson from a Local Repository <a name="update"></a>
130
+
131
+ If you previously created a Canvas lesson from a local repository, you should
132
+ have a `.canvas` file present in the repo. If that file is present, you can run
133
+ the following command to update the listed Canvas lesson automatically:
134
+
135
+ ```sh
136
+ github-to-canvas -a -lr --forkable
137
+ ```
138
+
139
+ If you don't have or want to use the `.canvas` file, you can also specify the
140
+ course ID and lesson ID:
141
+
142
+ ```sh
143
+ github-to-canvas -a --course <CANVAS_COURSE_ID> --id <CANVAS_LESSON_ID> -lr --forkable
144
+ ```
145
+
146
+ Canvas course and lesson IDs can be found in the URL.
147
+
148
+ #### Update a Canvas Lesson from a Remote Repository <a name="updateremote"></a>
149
+
150
+ You can update an existing Canvas course using a remote GitHub repository like so:
151
+
152
+ ```sh
153
+ github-to-canvas --align-from-github <URL> --course <COURSE_ID> --id <LESSON_ID> --type <TYPE> -lr --forkable
154
+ ```
155
+
156
+ This will read remote markdown using the provided URL and update a Canvas course
157
+ using the info provided. Type must match the existing lesson type.
158
+
159
+ ### Course Creation
160
+
161
+ This gem can create Canvas courses from scratch. These features
162
+ are still in development and may not work for all course designs. Quiz and
163
+ Discussion Topic lesson creation is still under development and will not work.
164
+
165
+ By providing a YAML file of the desired course structure, this gem can create a
166
+ course, add in modules, and populate those modules with pages and assignments.
167
+ The required YAML file must follow a specific structure. Using the steps below,
168
+ this gem can create the necessary YAML markup from existing Canvas courses.
169
+
170
+ #### Retrieve Canvas Course Information as YAML Markdown <a name="query"></a>
171
+
172
+ To create YAML markup of an existing Canvas course, use the following:
173
+
174
+ ```sh
175
+ github-to-canvas --query <CANVAS_COURSE_ID>
176
+ ```
177
+
178
+ This command will use the Canvas API to read a course's information, including
179
+ its module and lesson structure and lesson URLs. YAML markup will be produced as a result. This
180
+ output can be directly saved to a file, which will make the next step a little
181
+ easier:
182
+
183
+ ```sh
184
+ github-to-canvas --query <CANVAS_COURSE_ID> > query_results.yml
185
+ ```
186
+
187
+ The output will look similar to this:
188
+
189
+ ```yml
190
+ ---
191
+ :name: The Course's Title
192
+ :id: 111
193
+ :modules:
194
+ - :id: 2020
195
+ :name: First Module's Name
196
+ :lessons:
197
+ - id: slugified-page-name
198
+ title: This is the Title Of The First Lesson, a Page
199
+ indent: 0
200
+ type: Page
201
+ html_url: https://learning.flatironschool.com/courses/111/modules/items/27001
202
+ page_url: slugified-page-name
203
+ url: https://learning.flatironschool.com/api/v1/courses/111/pages/slugified-page-name
204
+ published: false
205
+ repository: ''
206
+ - id: 333
207
+ title: This is the Title Of The Second Lesson, an Assignment
208
+ indent: 1
209
+ type: Assignment
210
+ html_url: https://learning.flatironschool.com/courses/111/modules/items/27002
211
+ page_url: ''
212
+ url: https://learning.flatironschool.com/api/v1/courses/111/assignments/333
213
+ published: false
214
+ repository: ''
215
+ - :id: 2021
216
+ :name: Second Module's Name
217
+ :lessons:
218
+ ```
219
+
220
+ The output YAML will not include associated GitHub repository information.
221
+
222
+ #### Map GitHub Repositories to a Canvas Course YAML file <a name="map"></a>
223
+
224
+ To associate repositories to an existing course YAML, the following command can be used:
225
+
226
+ ```sh
227
+ github-to-canvas --map <YAML_FILE>
228
+ ```
229
+
230
+ For this feature to work, all Canvas lessons must have the GitHub HTML header
231
+ that is added using `-l`. This header contains the necessary repo information.
232
+
233
+ Save the output YAML to another file if you want to use it for later course
234
+ creation. For example:
235
+
236
+ ```sh
237
+ github-to-canvas --map query_results.yml > course_structure.yml
238
+ ```
239
+
240
+ The resulting YAML file will contain course information, the module and lesson
241
+ structure, and each lesson's associated GitHub repository.
242
+
243
+ #### Create New Canvas Course from a YAML file <a name="buildcourse"></a>
244
+
245
+ To create a Canvas course with this gem, you will need a correctly structured
246
+ YAML file with the course info, modules, lessons and associated lesson
247
+ repositories. In addition, all lessons must have a type (`Page` or
248
+ `Assignment`), a repository, and a title. Other lesson options are currently
249
+ ignored.
250
+
251
+ With the necessary data configured, use the `--build-course` option and pass in
252
+ the course's YAML file:
69
253
 
70
- ### Create a Canvas Lesson
254
+ ```sh
255
+ github-to-canvas --build-course course_structure.yml -lr --forkable
256
+ ```
257
+
258
+ This command will cause the following to happen:
71
259
 
72
- To create a Canvas lesson from a GitHub `README.md` file, at minimum, you will
73
- need to know the Canvas course id you are going to add to. This id can be found
74
- in the URL of the course.
260
+ - Create a Canvas course using the top level `:name:` in the YAML data
261
+ - Create the first module
262
+ - Create the first lesson using the repository, title and type, as well as additional command options
263
+ - Add the newly created lesson to the current module
264
+ - Create the second lesson and add it to the module...
265
+ - Repeate process until all modules and lessons are created
75
266
 
76
- Once you have the course id, you will need to do the following:
267
+ #### Update Lessons in an Existing Course from a YAML file <a name="updatecourse"></a>
77
268
 
78
- 1. Clone down the repository you'd like to push to Canvas.
79
- 2. Change directory into the new local repository
80
- 3. Run `github-to-canvas --create <your-course-id>` from inside the local repo
269
+ The GitHub to Canvas gem can be used to update all lessons in a course
270
+ with a single command. To do this, you will need an up-to-date course YAML file with repositories
271
+ mapped to each lesson.
81
272
 
82
- If everything is set up properly, `github-to-canvas` will create a Canvas lesson
83
- using `master` branch `README.md` and the name of the current folder. By
84
- default, if the repository contains folders, an **assignment** will be created.
85
- Otherwise, a **page** will be created.
273
+ ```sh
274
+ github-to-canvas --query <COURSE_ID> > query_results.yml
275
+ github-to-canvas --map query_results.yml > your_new_course.yml
276
+ ```
86
277
 
87
- ### Saving `.canvas` to GitHub
278
+ Use the resulting file (in this example, `your_new_course.yml`) to update all lessons in
279
+ a course based on their GitHub repo:
88
280
 
89
- Using `--save-to-github` will create a `.canvas` YAML file in the local repo and attempt to commit
90
- and push it to the remote repository. This file contains the course id, the newly
91
- created page id, and the Canvas URL to the lesson for future reference.
281
+ ```sh
282
+ github-to-canvas --update-course YAML_FILE -lr --forkable
283
+ ```
92
284
 
93
- If you create multiple Canvas lessons from the same repository, each lesson's
94
- Canvas data will be stored in the `.canvas` file.
285
+ The gem will iterate over the data and update every lesson according to the
286
+ associated repository.
95
287
 
96
- ### Update an Existing Canvas Lesson
288
+ ## Known Issues
97
289
 
98
- To update an existing Canvas lesson using a local repository, **a `.canvas` file
99
- must be present in the repo**, as it contains the lesson information for the
100
- Canvas API.
290
+ ### HTML Code Snippets Do Not Render
101
291
 
102
- 1. Clone down and/or change directory into the repository you'd like to update
103
- 2. Run `github-to-canvas --align` from inside the local repo
292
+ The Canvas API renders all HTML it receives. If your repository's markdown
293
+ includes HTML that is not meant to be rendered, the content will be rendered as
294
+ part of the page's HTML, resulting in unusual display errors in Canvas. Examples of
295
+ this would be lessons on HTML or JavaScript that include HTML code snippets.
104
296
 
105
- `github-to-canvas` will get the course id and page/assignment id from the
106
- `.canvas` file and update the associated Canvas lesson. If there are multiple
107
- Canvas lessons included in the `.canvas` file, each lesson will be updated (i.e.
108
- you have the same lesson in two courses created from one repository).
297
+ To fix any rendering issues in Canvas, go to the Canvas WYSIWYG editor for the
298
+ afflicted lesson. Click the HTML editor option (`</>` button in the lower right) to
299
+ switch to HTML.
109
300
 
110
- ### Options
301
+ Read the GitHub repo as HTML:
111
302
 
112
- This gem provides to the following options:
303
+ ```sh
304
+ github-to-canvas --read-from-github URL
305
+ ```
113
306
 
114
- * `-c, --create-lesson COURSE` - Creates a new Canvas lesson, converting the local repository's README.md to HTML. Adds .canvas file to remote repository
115
- * `-a, --align` - Updates a canvas lesson based on the local repository's README.md
116
- * `-n, --name NAME` - Sets the name of the new Canvas lesson to be created. If no name is given, repository folder name is used
117
- * `-t, --type TYPE` - Sets the type of Canvas lesson to be created (page, assignment or discussion). If no type, type decided based on repository structure
118
- * `-f, --file FILE` - Looks for and uses a markdown file in the currentt folder as source for conversion. Default file is README.md
119
- * `-b, --branch BRANCH` - Sets the repository branch used for lesson creation
120
- * `-s, --save-to-github` - Creates a local .canvas file and attempts to commit and push it to the GitHub repository
121
- * `-l, --fis-links` - Adds additional Flatiron School HTML after markdown conversion
122
- * `-r, --remove-header-and-footer` - Removes top lesson header and any Learn.co specific footer links before converting to HTML
123
- * `-o, --only-content` - For align functionality only - updates the HTML content of a lesson without changing the name
124
- * `-h, --help` - Outputs examples commands and all options
125
-
307
+ Copy the output HTML and paste it in to the Canvas editor. This should clear up
308
+ some larger page rendering issues, but may not fix all code snippets issues. To
309
+ fix these, switch back to the regular Canvas WYSIWYG editor, then open a second
310
+ tab to the GitHub repo you're converting from. Copy any HTML code snippets from
311
+ GitHub and paste them into the Canvas editor where they should be displayed.
312
+
313
+ The Canvas editor will treat the pasted HTML content as code and will
314
+ automatically replace some characters, escaping the code from the
315
+ normal rendering process.
316
+
317
+ Note that realigning after fixing this content with the gem will break the
318
+ rendering for these lessons again. A fix is planned for this issue, but has not
319
+ been implemented.
320
+
321
+ ### Multi-Line Code Snippets Render as a Single Line
322
+
323
+ The Github to Canvas gem uses an existing gem, Redcarpet, to handle the Markdown to HTML
324
+ conversion. This gem does not currently support multi-line codeblocks. This
325
+ functionality has been added in the Github to Canvas gem through monkeypatching.
326
+ This error should be resolved, but if you encounter code snippet rendering
327
+ issues, please open a new issue with a markdown example to replicate the error.
328
+
329
+ ### Markdown Formatting Issues Cause Errors in Canvas
330
+
331
+ An empty line should separate individual markdown headers, paragraphs and code snippets
332
+ in the markdown. Without these empty lines, the contents will be interpretted as one
333
+ continuous paragraph and ignore formatting.
334
+
335
+ ### New Repos That Use a `main` Branch
336
+
337
+ If you are using a new GitHub repository that uses a `main` branch, you may not be able to
338
+ create or update from a remote repository. You can still create and update from a local
339
+ repository by using the `--branch` (`-b`) option and specifying `main` as the branch.
340
+
341
+ A fix is planned for this issue, but not implemented.
342
+
343
+ ## Overview of GitHub to Canvas workflows
344
+
345
+ Using this gem, you can maintain Canvas courses in multiple ways - either by
346
+ creating and updating individual Canvas lessons or through the YAML file process.
347
+
348
+ At Flatiron School, we use the Canvas blueprint course feature. We use the
349
+ github-to-canvas gem to update the blueprint copy of lessons. These updates will appear
350
+ in future copies of the course or when synced down associated courses in Canvas.
351
+
352
+ ![github-to-canvas workflow chart](./images/github-to-canvas_workflow.png)
353
+
354
+ This can either be done with individual lessons or using a YAML files to keep
355
+ entire courses updated.
356
+
357
+ If you are using github-to-canvas in this way, changes should always be made on
358
+ the repository, not on Canvas. Any changes made only on Canvas will get
359
+ overwritten if the lesson is updated using the gem.
360
+
361
+ ## Common Options
362
+
363
+ - `--create-lesson`, `-c`: Requires a Canvas course ID. Creates a new Canvas
364
+ lesson, converting the local repository's README.md to HTML. Adds `.canvas`
365
+ file to remote repository
366
+ - `--align`, `-a`: Updates a canvas lesson based on the local repository's
367
+ README.md. If no other options are used, `--align` will look for a `.canvas`
368
+ file to know what to lesson to update
369
+ - `--course`: Provide a specific course ID. When used with `--id`, this can
370
+ override the default behavior for `--align`, allowing you to update any
371
+ existing lesson and ignore the `.canvas` file if present.
372
+ - `--id`: Provide a specific lesson ID. This can be found in the URL of the
373
+ specific lesson. For Pages, used the slugified lesson title.
374
+ - `--type`: Sets the type of Canvas lesson to be created (page, assignment or
375
+ discussion). If no type, type decided based on repository structure.
376
+ - `--name`: Can be used to override default naming behavior. By default, Canvas
377
+ lesson names are determined by the first top-level (`#`) header in the
378
+ repository's markdown file.
379
+ - `--fis-links`, `-l`: Adds additional Flatiron School HTML header after
380
+ markdown conversion, including links back to the GitHub repo and it's issue
381
+ form.
382
+ - `--forkable`: Adds a **Fork** button to the Flatiron School HTML header. For
383
+ use with custom Canvas JS to enable Canvas assignment forking workflow for
384
+ Flatiron School students.
385
+ - `--remove-header-and-footer`, `-r`: Removes top lesson header and any Flatiron
386
+ School specific footer links before converting to HTML. Removing top lesson
387
+ header prevents duplicate titles while viewing in Canvas.
388
+ - `--create-from-github`: Requires a GitHub repository URL. Also requires
389
+ `--course` and `--type`. Creates a Canvas lesson, reading from the remote repo
390
+ instead of a local repository. Repository must be public.
391
+ - `--align-from-github`: Requires a GitHub repo URL, `--course`, `--id`, and
392
+ `--type`. Updates a Canvas lesson from a remote repository.
393
+ - `--read-from-github`: Requires a GitHub repo URL. Reads a remote repository
394
+ and converts its contents to HTML, but does not push to Canvas.
395
+ - `--branch`, `-b`: Can be used when creating or aligning with a local repo to
396
+ specify which branch to use. Use this if you have a new repository that uses a
397
+ `main` branch instead of `master`.
398
+ - `--save-to-github`, `-s`: If you are are creating or aligning content locally,
399
+ the `.canvas` file is not automatically committed to the repo. This option will
400
+ attempt to commit and push the `.canvas` file to the remote repository.
401
+
402
+ Run `github-to-canvas --help` for additional options not listed in this Readme.
126
403
 
127
404
  ## Examples of Valid Images This Gem Can Convert
128
405
 
406
+ This gem can convert both standard inline markdown and HTML images.
407
+
129
408
  Inline Markdown:
130
409
 
131
410
  ![example in-line image](https://curriculum-content.s3.amazonaws.com/fewpjs/fewpjs-fetch-lab/Image_25_AsynchronousJavaScript.png)
@@ -1,6 +1,8 @@
1
+ require 'byebug'
1
2
  #!/usr/bin/env ruby
2
3
  require 'optparse'
3
4
  require 'github-to-canvas'
5
+
4
6
  options = {}
5
7
  OptionParser.new do |opts|
6
8
  opts.banner = <<-EOBANNER
@@ -29,23 +31,40 @@ OptionParser.new do |opts|
29
31
  Run these commands from inside a local GitHub repository. This gem is built for Flatiron School's internal use.
30
32
  Some default behaviors assume this, like the default Canvas API path.
31
33
 
32
- Example usage:
34
+ Create and Update Canvas Lessons From Inside a Local GitHub Repo Folder:
35
+
36
+ github-to-canvas --create-lesson 154 -> Creates a lesson in course 154, derives the name and type from the local repo
37
+ 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
38
+ github-to-canvas --create-lesson 154 --name "Fetch Lab" --type assignment -> Creates an assignment in course 154 with the provided name
39
+ 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
40
+ github-to-canvas --align -> Patches existing lessons in Canvas based on the .canvas file
41
+ github-to-canvas --align --fis-links -> Patches existing lessons in Canvas based on the .canvas file, adds additional Flatiron School specific HTML and meta-data
42
+ 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
43
+
44
+ Get Info on a Canvas Course, Lesson or GitHub Repo:
45
+
46
+ github-to-canvas --query COURSE -> Displays a course's modules and their lessons in course order as YAML
47
+ github-to-canvas --map YAML -> Uses a YAML file created with --query to retrieve repositories that were associated with Canvas lessons using --fis-links. Returns an updated YAML.
48
+ github-to-canvas --read-from-canvas CANVAS_LESSON_URL -> Retrieves a lesson's contents and information from Canvas
49
+ github-to-canvas --read-from-github GITHUB_URL -> Retrieves the provided GitHub markdown file, converted into HTML
50
+
51
+ Create and Update Canvas Lessons Using Remote GitHub Repositories:
52
+
53
+ github-to-canvas --create-from-github GITHUB_URL --course COURSE_ID --type TYPE -> Creates a lesson in the provided course using the remote GitHub URL. Source must be from a public repo.
54
+ github-to-canvas --align-from-github GITHUB_URL --course COURSE_ID --id LESSON_ID --type TYPE -> Updates a lesson in the provided course using the remote GitHub URL. Source must be from a public repo.
33
55
 
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
- github-to-canvas --align -> Patches existing lessons in Canvas based on the .canvas file
39
- github-to-canvas --align --fis-links -> Patches existing lessons in Canvas based on the .canvas file, adds additional Flatiron School specific HTML and meta-data
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
- github-to-canvas --info COURSE -> Displays a course's lesson and assignment names
56
+ Create and Update Canvas Courses From YAML:
57
+
58
+ github-to-canvas --build-course YAML_FILE -> Uses the provided YAML file to create a course, add modules and populate them with lessons using remote GitHub repositories
59
+ github-to-canvas --add-to-course YAML_FILE --course -> Uses a YAML file to a modules and lessons to an existing course.
60
+ github-to-canvas --update-course YAML_FILE -> Uses a YAML file to update lessons using their associated GitHub repositories (ignores module/course structure in YAML file)
42
61
 
43
62
  EOBANNER
44
63
 
45
64
  opts.on("-cCOURSE", "--create-lesson COURSE",
46
65
  "Creates a new canvas lesson, converting the local repository's README.md to HTML. Adds .canvas file to remote repository") do |course|
47
66
  options[:create_lesson] = true
48
- options[:course] = course
67
+ options[:course_id] = course
49
68
  end
50
69
  opts.on("-bBRANCH", "--branch BRANCH",
51
70
  "Sets the repository branch used for lesson creation") do |branch|
@@ -57,12 +76,16 @@ OptionParser.new do |opts|
57
76
  end
58
77
  opts.on("-tTYPE", "--type TYPE",
59
78
  "Sets the type Canvas lesson to be created (page or assignment). If no type, type decided based on repository structure") do |type|
60
- if type == 'page' || type == 'assignment' || type == 'discussion'
61
- options[:type] = type
62
- else
63
- puts "Invalid type. Defaulting to page"
64
- options[:type] = "page"
65
- end
79
+ # byebug
80
+ puts type.downcase
81
+ options[:type] = type.downcase
82
+ abort if type == 'quiz' || type == 'discussion'
83
+ # if type == 'page' || type == 'assignment' || type == 'discussion' || type == 'quiz' || type == 'Page' || type == 'Assignment' || type == 'Discussion' || type == 'Quiz'
84
+
85
+ # else
86
+ # puts "Invalid type. Defaulting to page"
87
+ # options[:type] = "page"
88
+ # end
66
89
  end
67
90
  opts.on("-fFILE", "--file FILE",
68
91
  "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|
@@ -93,8 +116,8 @@ OptionParser.new do |opts|
93
116
  options[:remove_header_and_footer] = true
94
117
  end
95
118
  opts.on("--course COURSE",
96
- "For align functionality only - updates the HTML content of a lesson using the provided course ID. Use with --id.") do |course|
97
- options[:course] = course
119
+ "For align functionality only - updates the HTML content of a lesson using the provided course ID. Use with --id.") do |course_id|
120
+ options[:course_id] = course_id
98
121
  end
99
122
  opts.on("--id ID",
100
123
  "For align functionality only - updates the HTML content of a lesson using the provided assignment or page ID. Use with --course.") do |id|
@@ -108,28 +131,151 @@ OptionParser.new do |opts|
108
131
  "Displays a course's lessons and assignments") do |course|
109
132
  options[:query] = course
110
133
  end
111
- opts.on("--remote",
112
- "Retrieves a Canvas lesson. Requires --course and --id") do |remote|
113
- options[:remote] = true
134
+ opts.on("--map YAML_FILE",
135
+ "REQUIRES -f or --file Associates canvas lessons with repositories. Use query to create required YAML file") do |file|
136
+ options[:map] = file
137
+ end
138
+ opts.on("--csv COURSE",
139
+ "Returns a course's lesson struction as CSV") do |course|
140
+ options[:csv] = course
141
+ end
142
+ opts.on("--read-from-canvas CANVAS_URL",
143
+ "Retrieves an existing Canvas lesson using the provided URL") do |url|
144
+ options[:read_from_canvas] = url
145
+ end
146
+ opts.on("--read-from-github GITHUB_URL",
147
+ "Converts an existing GitHub Readme to HTML using the provided URL. URL must be for a GitHub markdown file") do |url|
148
+ options[:read_from_github] = url
149
+ end
150
+ opts.on("--create-from-github GITHUB_URL",
151
+ "Creates a new Canvas lesson from a remote GitHub Readme. --course and --type options required") do |url|
152
+ options[:create_from_github] = url
153
+ end
154
+ # opts.on("--create-quiz-from-github GITHUB_URL",
155
+ # "Creates a new Canvas quiz from a remote GitHub YAML file. --course option required") do |url|
156
+ # options[:quiz_from_github] = url
157
+ # end
158
+ opts.on("--align-from-github GITHUB_URL",
159
+ "Aligns an existing Canvas lesson using a remote GitHub Readme. --course, --id, and --type options required") do |url|
160
+ options[:align_from_github] = url
161
+ end
162
+ opts.on("--build-course YAML_FILE",
163
+ "Creates Canvas course using provided YAML file") do |file|
164
+ options[:build_course] = file
165
+ end
166
+ opts.on("--add-to-course YAML_FILE",
167
+ "Creates Canvas course using provided YAML file") do |file|
168
+ options[:add_to_course] = file
169
+ end
170
+ opts.on("--update-course-lessons YAML_FILE",
171
+ "Updates all lessons in a course using remote repos in provided YAML file") do |file|
172
+ options[:update_course_lessons] = file
173
+ end
174
+ opts.on("--clone-from-yaml YAML_FILE",
175
+ "Iterates over provided course YAML file and clones repos locally") do |file|
176
+ options[:clone_from_yaml] = file
114
177
  end
115
-
116
178
 
117
179
  end.parse!
118
180
 
119
181
  if options[:version]
120
- GithubToCanvas.new(mode: 'version', course: nil)
182
+ GithubToCanvas.new(mode: 'version', course_id: nil)
183
+ abort
184
+ end
185
+
186
+ if options[:read_from_canvas]
187
+ GithubToCanvas.new(mode: 'canvas_read', filepath: options[:read_from_canvas])
188
+ abort
189
+ end
190
+
191
+ if options[:read_from_github]
192
+ GithubToCanvas.new(mode: 'github_read', filepath: options[:read_from_github])
193
+ abort
194
+ end
195
+
196
+ if options[:create_from_github]
197
+ if options[:course_id] && options[:type]
198
+ GithubToCanvas.new(mode: 'github_create',
199
+ filepath: options[:create_from_github],
200
+ course_id: options[:course_id],
201
+ type: options[:type],
202
+ remove_header_and_footer: !!options[:remove_header_and_footer],
203
+ forkable: !!options[:forkable],
204
+ fis_links: !!options[:fis])
205
+ else
206
+ puts 'Canvas course ID and lesson type required. Example: github-to-canvas --create-from-github URL --course ID --type TYPE'
207
+ end
208
+ abort
209
+ end
210
+
211
+ if options[:align_from_github]
212
+ if options[:course_id] && options[:type] && options[:id]
213
+ GithubToCanvas.new(mode: 'github_align',
214
+ filepath: options[:align_from_github],
215
+ course_id: options[:course_id],
216
+ type: options[:type],
217
+ id: options[:id],
218
+ name: options[:name],
219
+ remove_header_and_footer: !!options[:remove_header_and_footer],
220
+ forkable: !!options[:forkable],
221
+ fis_links: !!options[:fis])
222
+ else
223
+ puts 'Canvas course ID, lesson ID, and type required. Example: github-to-canvas --create-from-github URL --course COURSE_ID --id LESSON_ID --type TYPE'
224
+ end
225
+ abort
121
226
  end
122
227
 
123
228
  if options[:query]
124
- GithubToCanvas.new(mode: 'query', course: options[:query], id: options[:id])
229
+ GithubToCanvas.new(mode: 'query', course_id: options[:query], id: options[:id])
230
+ abort
125
231
  end
126
232
 
127
- if options[:remote]
128
- if !options[:course] || !options[:id]
129
- puts "Both --course and --id required when using --remote"
130
- abort
233
+ if options[:map]
234
+ GithubToCanvas.new(mode: 'map', file_to_convert: options[:map])
235
+ abort
236
+ end
237
+
238
+ if options[:csv]
239
+ GithubToCanvas.new(mode: 'csv', file_to_convert: options[:csv])
240
+ abort
241
+ end
242
+
243
+ if options[:build_course]
244
+ GithubToCanvas.new(mode: 'build_course',
245
+ file_to_convert: options[:build_course],
246
+ fis_links: !!options[:fis],
247
+ remove_header_and_footer: !!options[:remove_header_and_footer],
248
+ forkable: !!options[:forkable])
249
+ abort
250
+ end
251
+
252
+ if options[:add_to_course]
253
+ if options[:course_id]
254
+ GithubToCanvas.new(mode: 'add_to_course',
255
+ course_id: options[:course_id],
256
+ file_to_convert: options[:add_to_course],
257
+ fis_links: !!options[:fis],
258
+ remove_header_and_footer: !!options[:remove_header_and_footer],
259
+ forkable: !!options[:forkable])
260
+ else
261
+ puts '--course required'
131
262
  end
132
- GithubToCanvas.new(mode: 'remote', course: options[:course], id: options[:id])
263
+ abort
264
+ end
265
+
266
+ if options[:update_course_lessons]
267
+ GithubToCanvas.new(mode: 'update_course_lessons',
268
+ file_to_convert: options[:update_course_lessons],
269
+ fis_links: !!options[:fis],
270
+ remove_header_and_footer: !!options[:remove_header_and_footer],
271
+ forkable: !!options[:forkable])
272
+ abort
273
+ end
274
+
275
+ if options[:clone_from_yaml]
276
+ GithubToCanvas.new(mode: 'clone_course',
277
+ file_to_convert: options[:clone_from_yaml])
278
+ abort
133
279
  end
134
280
 
135
281
  if !options[:type]
@@ -174,7 +320,7 @@ end
174
320
 
175
321
  if options[:create_lesson]
176
322
  GithubToCanvas.new(mode: "create",
177
- course: options[:course],
323
+ course_id: options[:course_id],
178
324
  filepath: Dir.pwd,
179
325
  file_to_convert: options[:file_to_convert],
180
326
  branch: options[:branch],
@@ -189,7 +335,7 @@ end
189
335
 
190
336
  if options[:align]
191
337
  GithubToCanvas.new(mode: "align",
192
- course: options[:course],
338
+ course_id: options[:course_id],
193
339
  id: options[:id],
194
340
  filepath: Dir.pwd,
195
341
  file_to_convert: options[:file_to_convert],