github-to-canvas 0.0.57 → 0.1.3

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: 700beff2aa372bc0ddd7f8faf571f512530fbcaf554ce723c8906e3c4537fd89
4
- data.tar.gz: acd4476c34e0e79b4b042e8760be95ab80e8d88a44a6c425bbd351328ea01a1c
3
+ metadata.gz: d3d7cf49277d1fb40bb6a956a16865fded3e5a722b115313ab598c8b0ac16338
4
+ data.tar.gz: '01129c91256e4391343d2dd4bafc0c87acf57d7f8e0a4f3b040289ab045b6dea'
5
5
  SHA512:
6
- metadata.gz: 4e2717eb284c2521c05507a63e1de6f9e54ebac23cc37b06967857ce8f669a78355eaa33da631dddf06257167f5f21e871eefe7025ed9a2b8f3891e86570e744
7
- data.tar.gz: b5579232cc6a7f69f0c0e6dfcf9cc46f1a2078a7478c845e0f5f9db3c20710d67eb55b4861d0bd3c0357612f11fd841634c898bd962a7d339a832c2dda85c779
6
+ metadata.gz: ead1b6073842a1d3c65214ffc3e3cd8bd20048df97a878d8f12dd522655090e02b98f9fb2d45be70a16a044d05aea682bf5c6c71cd31ccd8a6ab9fb215591948
7
+ data.tar.gz: cb340a9d7f4910116ede731ad44cb44a02f90bf77dae5e632669d2b54879af2eab38a8ff1ebf4e1fd639ee1c68ac22fdd5ded4d3ae5f57cd283696b4e32b0834
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,366 @@ 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.
69
117
 
70
- ### Create a Canvas Lesson
118
+ #### Read a Remote Repository as HTML <a name="read"></a>
71
119
 
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.
120
+ To read the contents of a remote repo:
75
121
 
76
- Once you have the course id, you will need to do the following:
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.
77
128
 
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
129
+ #### Update a Canvas Lesson from a Local Repository <a name="update"></a>
81
130
 
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.
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
+ ```
86
138
 
87
- ### Saving `.canvas` to GitHub
139
+ If you don't have or want to use the `.canvas` file, you can also specify the
140
+ course ID and lesson ID:
88
141
 
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.
142
+ ```sh
143
+ github-to-canvas -a --course <CANVAS_COURSE_ID> --id <CANVAS_LESSON_ID> -lr --forkable
144
+ ```
92
145
 
93
- If you create multiple Canvas lessons from the same repository, each lesson's
94
- Canvas data will be stored in the `.canvas` file.
146
+ Canvas course and lesson IDs can be found in the URL.
95
147
 
96
- ### Update an Existing Canvas Lesson
148
+ #### Update a Canvas Lesson from a Remote Repository <a name="updateremote"></a>
97
149
 
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.
150
+ You can update an existing Canvas course using a remote GitHub repository like so:
101
151
 
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
152
+ ```sh
153
+ github-to-canvas --align-from-github <URL> --course <COURSE_ID> --id <LESSON_ID> --type <TYPE> -lr --forkable
154
+ ```
104
155
 
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).
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.
109
158
 
110
- ### Options
159
+ ### Course Creation
111
160
 
112
- This gem provides to the following options:
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.
113
164
 
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
-
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:
253
+
254
+ ```sh
255
+ github-to-canvas --build-course course_structure.yml -lr --forkable
256
+ ```
257
+
258
+ This command will cause the following to happen:
259
+
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
266
+
267
+ #### Update Lessons in an Existing Course from a YAML file <a name="updatecourse"></a>
268
+
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.
272
+
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
+ ```
277
+
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:
280
+
281
+ ```sh
282
+ github-to-canvas --update-course YAML_FILE -lr --forkable
283
+ ```
284
+
285
+ The gem will iterate over the data and update every lesson according to the
286
+ associated repository.
287
+
288
+ ## Known Issues
289
+
290
+ ### HTML Code Snippets Do Not Render
291
+
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.
296
+
297
+ To prevent HTML from being rendered, include the `--contains-html` option when
298
+ running the GitHub to Canvas gem. This replaces `<` and `>` characters with HTML
299
+ charset values wrapped in `span` elements. This will stop Canvas from rendering
300
+ the HTML.
301
+
302
+ If your markdown contains a mix of HTML that should and should not be rendered,
303
+ you will need to either replace HTML that you want to be rendered with markdown
304
+ syntax equivalents. For example, HTML you want to display as code and an `<img>`
305
+ element you want to render as the image itself, replace the `<img>` tag with
306
+ markdown syntax (`![alt text](url)`).
307
+
308
+ The one exception is the `<iframe>` element. There is no way to easily embed
309
+ videos in GitHub markdown without HTML, so this tag will always be allowed to
310
+ render in Canvas, whether or not you use `--contains-html`.
311
+
312
+ If you have HTML related rendering issues in Canvas that can't be fixed with
313
+ `--contains-html`:
314
+
315
+ - Go to the Canvas WYSIWYG editor for the afflicted lesson.
316
+ - Click the HTML editor option (`</>` button in the lower right) to switch to
317
+ HTML.
318
+ - Read the GitHub repo as HTML:
319
+
320
+ ```sh
321
+ github-to-canvas --read-from-github URL
322
+ ```
323
+
324
+ - Copy the output HTML and paste it in to the Canvas editor. This should clear up
325
+ some larger page rendering issues, but may not fix all code snippets issues.
326
+ - Switch back to the regular Canvas WYSIWYG editor
327
+ - Open a second tab to the GitHub repo you're converting from.
328
+ - Copy any HTML code snippets from GitHub and paste them into the Canvas editor
329
+ where they should be displayed.
330
+
331
+ The Canvas editor will treat the pasted HTML content as code and will
332
+ automatically replace some characters, escaping the code from the
333
+ normal rendering process.
334
+
335
+ Note that realigning after fixing this content may overwrite fixes.
336
+
337
+ ### Multi-Line Code Snippets Render as a Single Line
338
+
339
+ The Github to Canvas gem uses an existing gem, Redcarpet, to handle the Markdown to HTML
340
+ conversion. This gem does not currently support multi-line codeblocks. This
341
+ functionality has been added in the Github to Canvas gem through monkeypatching.
342
+ This error should be resolved, but if you encounter code snippet rendering
343
+ issues, please open a new issue with a markdown example to replicate the error.
344
+
345
+ ### Markdown Formatting Issues Cause Errors in Canvas
346
+
347
+ An empty line should separate individual markdown headers, paragraphs and code snippets
348
+ in the markdown. Without these empty lines, the contents will be interpretted as one
349
+ continuous paragraph and ignore formatting.
350
+
351
+ ### New Repos That Use a `main` Branch
352
+
353
+ If you are using a new GitHub repository that uses a `main` branch, you may not be able to
354
+ create or update from a remote repository. You can still create and update from a local
355
+ repository by using the `--branch` (`-b`) option and specifying `main` as the branch.
356
+
357
+ A fix is planned for this issue, but not implemented.
358
+
359
+ ## Overview of GitHub to Canvas workflows
360
+
361
+ Using this gem, you can maintain Canvas courses in multiple ways - either by
362
+ creating and updating individual Canvas lessons or through the YAML file process.
363
+
364
+ At Flatiron School, we use the Canvas blueprint course feature. We use the
365
+ github-to-canvas gem to update the blueprint copy of lessons. These updates will appear
366
+ in future copies of the course or when synced down associated courses in Canvas.
367
+
368
+ ![github-to-canvas workflow chart](./images/github-to-canvas_workflow.png)
369
+
370
+ This can either be done with individual lessons or using a YAML files to keep
371
+ entire courses updated.
372
+
373
+ If you are using github-to-canvas in this way, changes should always be made on
374
+ the repository, not on Canvas. Any changes made only on Canvas will get
375
+ overwritten if the lesson is updated using the gem.
376
+
377
+ ## Common Options
378
+
379
+ - `--create-lesson`, `-c`: Requires a Canvas course ID. Creates a new Canvas
380
+ lesson, converting the local repository's README.md to HTML. Adds `.canvas`
381
+ file to remote repository
382
+ - `--align`, `-a`: Updates a canvas lesson based on the local repository's
383
+ README.md. If no other options are used, `--align` will look for a `.canvas`
384
+ file to know what to lesson to update
385
+ - `--course`: Provide a specific course ID. When used with `--id`, this can
386
+ override the default behavior for `--align`, allowing you to update any
387
+ existing lesson and ignore the `.canvas` file if present.
388
+ - `--id`: Provide a specific lesson ID. This can be found in the URL of the
389
+ specific lesson. For Pages, used the slugified lesson title.
390
+ - `--type`: Sets the type of Canvas lesson to be created (page, assignment or
391
+ discussion). If no type, type decided based on repository structure.
392
+ - `--name`: Can be used to override default naming behavior. By default, Canvas
393
+ lesson names are determined by the first top-level (`#`) header in the
394
+ repository's markdown file.
395
+ - `--fis-links`, `-l`: Adds additional Flatiron School HTML header after
396
+ markdown conversion, including links back to the GitHub repo and it's issue
397
+ form.
398
+ - `--forkable`: Adds a **Fork** button to the Flatiron School HTML header. For
399
+ use with custom Canvas JS to enable Canvas assignment forking workflow for
400
+ Flatiron School students.
401
+ - `--remove-header-and-footer`, `-r`: Removes top lesson header and any Flatiron
402
+ School specific footer links before converting to HTML. Removing top lesson
403
+ header prevents duplicate titles while viewing in Canvas.
404
+ - `--create-from-github`: Requires a GitHub repository URL. Also requires
405
+ `--course` and `--type`. Creates a Canvas lesson, reading from the remote repo
406
+ instead of a local repository. Repository must be public.
407
+ - `--align-from-github`: Requires a GitHub repo URL, `--course`, `--id`, and
408
+ `--type`. Updates a Canvas lesson from a remote repository.
409
+ - `--read-from-github`: Requires a GitHub repo URL. Reads a remote repository
410
+ and converts its contents to HTML, but does not push to Canvas.
411
+ - `--branch`, `-b`: Can be used when creating or aligning with a local repo to
412
+ specify which branch to use. Use this if you have a new repository that uses a
413
+ `main` branch instead of `master`.
414
+ - `--save-to-github`, `-s`: If you are are creating or aligning content locally,
415
+ the `.canvas` file is not automatically committed to the repo. This option will
416
+ attempt to commit and push the `.canvas` file to the remote repository.
417
+
418
+ Run `github-to-canvas --help` for additional options not listed in this Readme.
126
419
 
127
420
  ## Examples of Valid Images This Gem Can Convert
128
421
 
422
+ This gem can convert both standard inline markdown and HTML images.
423
+
129
424
  Inline Markdown:
130
425
 
131
426
  ![example in-line image](https://curriculum-content.s3.amazonaws.com/fewpjs/fewpjs-fetch-lab/Image_25_AsynchronousJavaScript.png)