| 1 | Contributing Obvious Widgets |
| 2 | ============================ |
| 3 | |
| 4 | So, you want to contribute to the Obvious project? Well of course you do! I |
| 5 | guess that's pretty clear. I mean, anyone could tell, right? Obviously. |
| 6 | |
| 7 | ... |
| 8 | |
| 9 | So lets get started. |
| 10 | |
| 11 | Patching An Existing Widget |
| 12 | --------------------------- |
| 13 | |
| 14 | If you want to just improve our existing widgets by adding settings and |
| 15 | features, it's pretty easy. Some things to watch out for: |
| 16 | - Style! Make sure that the code you write fits with the general style of the |
| 17 | widget. In particular, you should use the same indentation pattern that the |
| 18 | code uses. Also, trailing whitespace is bad. Try to avoid adding space at |
| 19 | the ends of lines. This wastes bytes and is considered poor form. Anyway, |
| 20 | you probably get the idea. |
| 21 | - Clarity. Your code should be easy to understand, maintainable, and |
| 22 | modularized. You should also avoid code duplication wherever possible by |
| 23 | adding functions. If something is unclear, and you can't write it in such a |
| 24 | way that it will be clear, explain it with a comment. |
| 25 | - Regressions. Please _test_ your changes before submitting to make sure that |
| 26 | not only they work, but have not broken other parts of the widget! |
| 27 | - Options. If you add or remove options, make sure the top-level README file |
| 28 | reflects the changes. See "Adding A New Widget"'s section on this. |
| 29 | |
| 30 | Adding A New Widget |
| 31 | ------------------- |
| 32 | |
| 33 | It's also understandable that people want to add their own widgets to the |
| 34 | Obvious repository. That's fantastic. Adding your useful widgets to Obvious |
| 35 | makes them available for everyone. However, there are a few things that you |
| 36 | need to know about the structure of Obvious. Note that a lot of the stuff from |
| 37 | the section "Patching An Existing Widget" also apply here. |
| 38 | |
| 39 | ### File Structure |
| 40 | |
| 41 | obvious |
| 42 | | |
| 43 | |-- init.lua |
| 44 | | |
| 45 | |-- battery |
| 46 | | | |
| 47 | | |-- init.lua |
| 48 | | `-- readme |
| 49 | . |
| 50 | |
| 51 | In general, Obvious widgets are laid as above. The main file, obvious/init.lua |
| 52 | has the definition of the Obvious module in general. When adding a new widget, |
| 53 | you want to also add it to this file. The name that you want to add is the same |
| 54 | as the folder you'll be making. |
| 55 | |
| 56 | Then, you want to make that folder. In the example above, that is "battery". |
| 57 | Inside the folder, you want to have at least "init.lua" and "readme". The |
| 58 | init.lua file will be run first, the readme explains to the user what your |
| 59 | module does and how to implement it, as well as any settings. Feel free to add |
| 60 | more .lua files in the folder if you need them. |
| 61 | |
| 62 | ### Your init.lua |
| 63 | |
| 64 | This is your main file for your widget. Add other files if necessary for the |
| 65 | sake of organization, but this is all you really need. Refer to other modules |
| 66 | and documentation for how to write this kind of file. In general, the structure |
| 67 | is: |
| 68 | |
| 69 | * Get variables and modules from the rc.lua and Awesome |
| 70 | * Declare your module |
| 71 | * Write your code using the variables defined |
| 72 | * Write your public settings interface (see below) |
| 73 | |
| 74 | ### Your settings |
| 75 | |
| 76 | For settings, we have the standard that your module must have a collection of |
| 77 | functions named `set_<setting>`. These are the access to the module's settings |
| 78 | and can otherwise be whatever you want. |
| 79 | |
| 80 | These then are used from the rc.lua like: |
| 81 | |
| 82 | obvious.module.set_something(foo) |
| 83 | |
| 84 | And that should be all it takes for the user. |
| 85 | |
| 86 | ### Your data |
| 87 | |
| 88 | If the widget gathers nontrivial data (i.e. wlan signal strength, battery charge, |
| 89 | but _not_ the current time, as that's just one function call away), you should |
| 90 | supply a function called `get_data()` which returns nil on failure and a hashtable |
| 91 | with the collected data otherwise. This is so other people can build on your work |
| 92 | (the true spirit of open source, right? :P) and create different ways of visualizing |
| 93 | the data gathered by your widget without duplicating code (which is why your widget |
| 94 | should also use the `get_data()` function). |
| 95 | |
| 96 | ### Top-level init file |
| 97 | |
| 98 | If someone does `require("obvious")`, the behaviour is to import all widgets. |
| 99 | The way this is accomplished is by making an "obvious" module that requires |
| 100 | all of the sub-modules. In short, if you've created a new sub-module, you |
| 101 | should add your sub-module to the list of things that is required by the |
| 102 | init.lua in the root folder. |
| 103 | |
| 104 | ### Top-level README |
| 105 | |
| 106 | The top-level README is an overview of what features each widget sub-module |
| 107 | supports and provides. It is a listing of the options available and what |
| 108 | views it supports (like text-only, progress bar, etc.). When creating a new |
| 109 | widget, you should add your overview to the top-level README. |
| 110 | |
| 111 | ### Your readme |
| 112 | |
| 113 | Your "readme" is the explanation for the user. As such, it has a rough layout: |
| 114 | |
| 115 | * Widget Name |
| 116 | * Description of widget. |
| 117 | * Explanation of available settings. |
| 118 | * Explanation of how to integrate it into your rc.lua. |
| 119 | |
| 120 | The exact way you do this doesn't matter, but please try to stick to this kind |
| 121 | of ordering/layout. |
| 122 | |
| 123 | Submitting Your Changes |
| 124 | ----------------------- |
| 125 | |
| 126 | Once you've written a tidy, well-fitting, clear patch with no bugs, you should |
| 127 | submit it. We'd seriously love to have it. Some ways: |
| 128 | * Commit it and use git-format-branch to create a patch-email. Then send this |
| 129 | e-mail to one of the developers of obvious if you can find their e-mails, or |
| 130 | to one of the awesome mailing lists which we tend to read. We then can take |
| 131 | it, read it, possibly reply to it with suggestions for improvement, or apply |
| 132 | it to the obvious project. |
| 133 | * You can put your changes into your own personal git repo on the web and |
| 134 | request a pull. Use the command git request-pull for this. This makes a bit |
| 135 | of formatted text that tells us what changes you've made and where to get |
| 136 | it. Again, e-mail this text up to us somewhere. |
| 137 | * Also, we're generally pretty laid back. If we know you, trust you to write |
| 138 | decent code, and know that you want to help regularly, we can probably just |
| 139 | agree to give you commit access to the main Obvious repo. |