Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 54e4cba82e9b3c35d00c4b497d9912f695296ec2 @andrewschaaf committed May 13, 2011
Showing with 167 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +23 −0 LICENSE.txt
  3. +42 −0 README.md
  4. +101 −0 foss-credits.rb
@@ -0,0 +1 @@
+.DS_Store
@@ -0,0 +1,23 @@
+
+Copyright (c) 2011 https://github.com/andrewschaaf/foss-credits/contributors
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
+
+## Example
+
+<pre>
+
+html = foss_credits_html({
+ :items => [
+ {
+ :name => "foss-credits",
+ :website => "https://github.com/andrewschaaf/foss-credits",
+ :license => &lt;&lt;-END_851063A0897C00
+
+Copyright (c) 2011 https://github.com/andrewschaaf/foss-credits/contributors
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+END_851063A0897C00
+ },
+ # ...
+ ]
+})
+
+</pre>
@@ -0,0 +1,101 @@
+
+
+def foss_credits_html(info)
+ return "<html><head>#{js}#{css}</head><body>#{body(info)}</body></html>"
+end
+
+
+def body(info)
+ arr = []
+ info[:items].each_index do |i|
+ item = info[:items][i]
+ arr.push(' <div class="item">
+ <table class="header">
+ <tr>
+ <td class="header_left">
+ ' + item[:name] + '
+ </td>
+ <td class="header_right">
+ <a href="' + item[:website] + '">website</a>
+ &ndash;
+ <a href="#"
+ onclick="toggleLicense(' + i.to_s + ');"
+ id="toggler_' + i.to_s + '">
+ show license
+ </a>
+ </td>
+ </tr>
+ </table>
+ <div class="license" id="license_' + i.to_s + '">
+ <pre>
+' + item[:license] + '
+</pre>
+ </div>
+ </div>')
+ end
+ arr.join "\n\n"
+end
+
+
+def js()
+ <<-END
+ <script type="text/javascript" charset="utf-8">
+ var toggleLicense = function(n) {
+ var license = document.getElementById("license_" + n);
+ var toggler = document.getElementById("toggler_" + n);
+ if (license.style.display == 'block') {
+ // hide license
+ license.style.display = 'none';
+ toggler.innerHTML = "show license";
+ }
+ else {
+ // show license
+ license.style.display = 'block';
+ toggler.innerHTML = "hide license";
+ }
+ };
+ </script>
+ END
+end
+
+def css()
+ <<-END
+ <style type="text/css" media="screen">
+
+ body {
+ font-family: Arial, sans-serif;
+ }
+
+ .item {
+ margin: 15px;
+ background: #B7B7B7;
+ -webkit-border-radius: 5px;
+ padding-left: 14px;
+ padding-right: 14px;
+ padding-bottom: 1px;
+ }
+ .header {
+ width: 100%;
+ cellspacing: 0;
+ }
+ .header_left {
+ text-align: left;
+ font-size: 18px;
+ font-weight: bold;
+ }
+ .header_right {
+ text-align: right;
+ }
+ .license {
+ display: none;
+ background: #FBFBFB;
+ -webkit-border-radius: 5px;
+ }
+ .license pre {
+ padding: 10px;
+ }
+
+ </style>
+ END
+end
+

0 comments on commit 54e4cba

Please sign in to comment.