├── .gitignore ├── LICENSE ├── README.md ├── Rakefile ├── bin └── gist-compile ├── gc_products ├── gists.html ├── gists.json └── gists.md ├── gist-compile.gemspec └── lib └── json-serializer.rb /.gitignore: -------------------------------------------------------------------------------- 1 | private/ 2 | *.gem -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Clay McLeod 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gist-compile 2 | 3 | [![Join the chat at https://gitter.im/claymcleod/gist-compile](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/claymcleod/gist-compile?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Gem Version](https://badge.fury.io/rb/gist-compile.svg)](http://badge.fury.io/rb/gist-compile) 4 | 5 | "gist-compile" is a tool I created to index your Github Gists (and the backend to a website I created, called [Gnippets](http://gnippets.com). Currently, the supported outputs are JSON, Markdown, and HTML. [View the results here](https://github.com/claymcleod/gist-compile/tree/master/gc_products). The usage is simple: 6 | 7 | ## Downloading using Rubygems 8 | 9 | 1. Install the gem using Rubygems ```gem install gist-compile``` 10 | 2. Start gist-compile! ```gist-compile start -u "claymcleod"``` 11 | 12 | ## Downloading manually 13 | 14 | 1. Clone the repo 15 | 2. Change the gist-compile directory ```cd ``` 16 | 3. Make the binary executable ```chmod +x bin/gist-compile``` 17 | 4. Start gist-compile! ```bin/gist-compile start -u "claymcleod"``` 18 | 19 | 20 | ## Formatting your gists 21 | 22 | Before you run gist-compile, you should format each Gist you want compiled like so: 23 | 24 | ``` 25 | # Title: Simple Ruby Datamining Example 26 | # Authors: Clay McLeod 27 | # Description: La tee 28 | # da 29 | # Section: Learning Ruby 30 | # Subsection: Simple Examples 31 | 32 | ...code... 33 | ``` 34 | 35 | A few rules: 36 | 37 | 1. This comment must be at the top of your gist file (shebangs are the only thing that may go above them) 38 | 2. You must format your comment using single line comment character (multi-line comments not supported!) 39 | 3. You must include a section and a subsection. 40 | 41 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | -------------------------------------------------------------------------------- /bin/gist-compile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # coding: utf-8 3 | 4 | require "uri" 5 | require "json" 6 | require "thor" 7 | require "paint" 8 | require "rubygems" 9 | require "nokogiri" 10 | require "fileutils" 11 | require "rest-client" 12 | require "json-serializer" 13 | 14 | class GistCompile < Thor 15 | 16 | GIST_JSON_LOC = "./gc_products/gists.json" 17 | GIST_MD_LOC ="./gc_products/gists.md" 18 | GIST_HTML_LOC ="./gc_products/gists.html" 19 | GIST_PROD_DIR = File.expand_path("../.", GIST_JSON_LOC) 20 | 21 | GIST_BASE_URL = "https://gist.github.com" 22 | GIST_USERCONTENT_BASE_URL = "https://gist.githubusercontent.com" 23 | GIST_XPATH_IDENTIFIER = "//*[@id=\"js-flash-container\"]/div/div/div/div/div/span/a[3]" 24 | 25 | GIST_METADATA_HOOKS = Hash.new 26 | GIST_METADATA_HOOKS["Title"] = "Title:" 27 | GIST_METADATA_HOOKS["Authors"] = "Authors:" 28 | GIST_METADATA_HOOKS["Description"] = "Description:" 29 | GIST_METADATA_HOOKS["Section"] = "Section:" 30 | GIST_METADATA_HOOKS["Subsection"] = "Subsection:" 31 | 32 | no_commands do 33 | def load_gists(usernames) 34 | thread_arr = [] 35 | metadata = [] 36 | elements = [] 37 | gists_data = Hash.new 38 | username_urls = [] 39 | 40 | usernames.each do |u| 41 | begin 42 | username_urls.push(URI::join(GIST_BASE_URL+'/', u.strip()).to_s) 43 | rescue => e 44 | puts "Uh oh! Could not find user with name: "+u.strip() 45 | end 46 | end 47 | 48 | username_urls.each do |username_url| 49 | page = 1 50 | while page < 1000 51 | begin 52 | gist_url_current_page = URI::join(username_url+'/', "?page=#{page}").to_s 53 | raw_html = Nokogiri::HTML(RestClient.get(gist_url_current_page)) 54 | new_elements = raw_html.css(GIST_XPATH_IDENTIFIER) 55 | if new_elements.length == 0 56 | break 57 | else 58 | elements.concat(new_elements) 59 | end 60 | page = page + 1 61 | rescue => e 62 | if page == 1 63 | puts "Error loading user: "+username_url.sub(GIST_BASE_URL, '').sub('/','') 64 | end 65 | break 66 | end 67 | end 68 | end 69 | 70 | puts "Processing #{elements.length} gists..." 71 | 72 | elements.each do |element| 73 | thread_arr.push( 74 | Thread.new { 75 | individual_gist_url = URI::join(GIST_BASE_URL, element['href']+'/').to_s 76 | individual_gist_url_raw = URI::join(GIST_USERCONTENT_BASE_URL, element['href']+'/', 'raw').to_s 77 | individual_gist_html = Nokogiri::HTML(RestClient.get(individual_gist_url_raw)) 78 | metadata_for_gist = process_raw_gist(individual_gist_html.xpath("//*/body/p")[0].text) 79 | if metadata_for_gist != nil && !metadata_for_gist.empty? 80 | $stdout.write(" • #{individual_gist_url}: " + Paint["[", :yellow] + Paint["OK", :green] + Paint["]",:yellow]+"\r\n") 81 | $stdout.flush 82 | GIST_METADATA_HOOKS.each do |key, value| 83 | if !metadata_for_gist.key? key 84 | metadata_for_gist[key] = nil 85 | end 86 | end 87 | metadata_for_gist["URL"] = individual_gist_url 88 | metadata_for_gist["URL_RAW"] = individual_gist_url_raw 89 | metadata_for_gist["URL_USER"] = /github.com\/[A-Za-z0-9]*/.match(individual_gist_url) 90 | metadata.push(metadata_for_gist) 91 | else 92 | puts " • #{individual_gist_url}: " + Paint["[", :yellow] + Paint["ERR", :red] + Paint["]",:yellow] 93 | end 94 | } 95 | ) 96 | end 97 | 98 | thread_arr.each{ |t| t.join() } 99 | 100 | FileUtils::mkdir_p GIST_PROD_DIR 101 | 102 | File.open(GIST_JSON_LOC,"w") do |f| 103 | pretty_string = JSON.pretty_generate(metadata.sort_by {|item| item["Title"]}) 104 | f.write(pretty_string) 105 | f.close() 106 | end 107 | end 108 | 109 | def process_raw_gist (raw_text) 110 | metadata = Hash.new 111 | 112 | comment_char = nil 113 | lines = raw_text.lines() 114 | last_known_key = nil 115 | 116 | hooks_remaining = GIST_METADATA_HOOKS.clone 117 | 118 | for index in 0..lines.length-1 119 | stripped_line = lines[index].strip() 120 | if stripped_line != nil && !stripped_line.empty? 121 | if stripped_line.start_with?("#!") 122 | next 123 | end 124 | 125 | if comment_char == nil 126 | index = stripped_line.index(GIST_METADATA_HOOKS["Title"]) 127 | if index == nil 128 | return nil 129 | else 130 | comment_char = stripped_line[0..index-1].strip() 131 | end 132 | end 133 | if stripped_line.start_with?(comment_char) 134 | stripped_line = stripped_line.sub(comment_char,'').strip() 135 | if stripped_line.empty? 136 | last_known_key = nil 137 | break 138 | end 139 | hook_data = search_line_for_hooks(hooks_remaining, last_known_key, stripped_line) 140 | if hook_data == nil 141 | break 142 | else 143 | parsed_key = hook_data[0] 144 | parsed_value = hook_data[1] 145 | 146 | last_known_key = parsed_key 147 | if metadata.key? parsed_key # is the key already in the hash? 148 | metadata[parsed_key] = metadata[parsed_key] + " #{parsed_value}" # append 149 | else 150 | metadata[parsed_key] = parsed_value 151 | end 152 | end 153 | else 154 | last_known_key = nil 155 | break 156 | end 157 | end 158 | end 159 | 160 | return metadata 161 | end 162 | 163 | def search_line_for_hooks(hooks_remaining, last_known_key, line) 164 | hooks_remaining.each do |key, value| 165 | if line.include? value 166 | hooks_remaining.delete(key) 167 | return [key, line.sub(value, '')] 168 | end 169 | end 170 | 171 | if last_known_key != nil 172 | return [last_known_key, line]; 173 | end 174 | 175 | return nil 176 | end 177 | end 178 | 179 | desc "start", "Run the gist-compile" 180 | method_option :username, :aliases => "-u", :desc => "username(s) to run with, seperated by comma: \"claymcleod, othername\"" 181 | method_option :linkauthor, :aliases => "--link-author", :desc => "When serializing in HTML, the authors page will be linked", :default => false 182 | def start 183 | usernames = options[:username] 184 | linkauthor = options[:linkauthor] 185 | 186 | if usernames == nil 187 | puts "You must specify a username! (eg. -u \"claymcleod\")" 188 | return 189 | end 190 | 191 | load_gists(usernames.split(",")) 192 | serializer = JSONSerializer.new(File.open(GIST_JSON_LOC,"r").read, linkauthor) 193 | serializer.to_md(GIST_MD_LOC) 194 | serializer.to_html(GIST_HTML_LOC) 195 | end 196 | end 197 | 198 | GistCompile.start(ARGV) 199 | 200 | -------------------------------------------------------------------------------- /gc_products/gists.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Generated by gist-compile at 2015-02-22 19:29:52 8 |
9 | 10 |

Objective-C

11 |
12 |

System Events

13 | 14 |

Sending Keystrokes

15 | 20 |
21 | 22 |

Python

23 |
24 |

Data Science

25 | 26 |

Reddit Data Mining Script

27 | 32 |

General

33 | 34 |

Regular Expressions with Python

35 | 40 |

Interesting Problems

41 | 42 |

Edit Distance

43 | 48 |

Max subarray

49 | 54 |

Sort nuts and bolts

55 | 60 |
61 | 62 |

Ruby

63 |
64 |

Data Science

65 | 66 |

Simple Ruby Datamining Example

67 | 72 |
73 | 74 |

Swift

75 |
76 |

General

77 | 78 |

Regular Expressions with Swift

79 | 84 |

UI

85 | 86 |

Listening for Tap Gestures

87 | 92 |

UIDynamics

93 | 98 |

Variables

99 | 100 |

Lazy Initialization of Swift Variables

101 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /gc_products/gists.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "Title": " Edit Distance", 4 | "Authors": " Clay McLeod", 5 | "Description": " Python edit distance problem", 6 | "Section": " Python", 7 | "Subsection": " Interesting Problems", 8 | "URL": "https://gist.github.com/claymcleod/f9ce092cfed501408ee6/", 9 | "URL_RAW": "https://gist.githubusercontent.com/claymcleod/f9ce092cfed501408ee6/raw", 10 | "URL_USER": "github.com/claymcleod" 11 | }, 12 | { 13 | "Title": " Lazy Initialization of Swift Variables", 14 | "Authors": " Clay McLeod", 15 | "Description": " An example of how to create a variable using lazy initialization in the Swift programming language.", 16 | "Section": " Swift", 17 | "Subsection": " Variables", 18 | "URL": "https://gist.github.com/claymcleod/d66f08c06918cee065be/", 19 | "URL_RAW": "https://gist.githubusercontent.com/claymcleod/d66f08c06918cee065be/raw", 20 | "URL_USER": "github.com/claymcleod" 21 | }, 22 | { 23 | "Title": " Listening for Tap Gestures", 24 | "Authors": " Clay McLeod", 25 | "Description": " How to handle tap gestures on a view controller.", 26 | "Section": " Swift", 27 | "Subsection": " UI", 28 | "URL": "https://gist.github.com/claymcleod/b46a1c84e39cddc868e7/", 29 | "URL_RAW": "https://gist.githubusercontent.com/claymcleod/b46a1c84e39cddc868e7/raw", 30 | "URL_USER": "github.com/claymcleod" 31 | }, 32 | { 33 | "Title": " Max subarray", 34 | "Authors": " Clay McLeod", 35 | "Description": " Finds the max subarray of an array of integers, in O(nlogn) time", 36 | "Section": " Python", 37 | "Subsection": " Interesting Problems", 38 | "URL": "https://gist.github.com/claymcleod/26e2f380f4dda468fd56/", 39 | "URL_RAW": "https://gist.githubusercontent.com/claymcleod/26e2f380f4dda468fd56/raw", 40 | "URL_USER": "github.com/claymcleod" 41 | }, 42 | { 43 | "Title": " Reddit Data Mining Script", 44 | "Authors": " Clay McLeod", 45 | "Description": " This script mines JSON data from the Reddit front page and stores it as a CSV file for analysis.", 46 | "Section": " Python", 47 | "Subsection": " Data Science", 48 | "URL": "https://gist.github.com/claymcleod/1613590bbfc8203c0797/", 49 | "URL_RAW": "https://gist.githubusercontent.com/claymcleod/1613590bbfc8203c0797/raw", 50 | "URL_USER": "github.com/claymcleod" 51 | }, 52 | { 53 | "Title": " Regular Expressions with Python", 54 | "Authors": " Clay McLeod", 55 | "Description": " Shows you how to find all instances of a regular expression in a string", 56 | "Section": " Python", 57 | "Subsection": " General", 58 | "URL": "https://gist.github.com/claymcleod/a30752456fbb5efe8bcf/", 59 | "URL_RAW": "https://gist.githubusercontent.com/claymcleod/a30752456fbb5efe8bcf/raw", 60 | "URL_USER": "github.com/claymcleod" 61 | }, 62 | { 63 | "Title": " Regular Expressions with Swift", 64 | "Authors": " Clay McLeod", 65 | "Description": " A brief overview of regular expressions with Swift", 66 | "Section": " Swift", 67 | "Subsection": " General", 68 | "URL": "https://gist.github.com/claymcleod/39214f470d71363d6410/", 69 | "URL_RAW": "https://gist.githubusercontent.com/claymcleod/39214f470d71363d6410/raw", 70 | "URL_USER": "github.com/claymcleod" 71 | }, 72 | { 73 | "Title": " Sending Keystrokes", 74 | "Authors": " Clay McLeod", 75 | "Description": " An example of how to send keystrokes to a window", 76 | "Section": " Objective-C", 77 | "Subsection": " System Events", 78 | "URL": "https://gist.github.com/claymcleod/9d0a0a6eda00e8754546/", 79 | "URL_RAW": "https://gist.githubusercontent.com/claymcleod/9d0a0a6eda00e8754546/raw", 80 | "URL_USER": "github.com/claymcleod" 81 | }, 82 | { 83 | "Title": " Simple Ruby Datamining Example", 84 | "Authors": " Clay McLeod", 85 | "Description": " Mines data every minute concerning how many people are logged into a certain subreddit.", 86 | "Section": " Ruby", 87 | "Subsection": " Data Science", 88 | "URL": "https://gist.github.com/claymcleod/b3adc0a5ca47b716dd6b/", 89 | "URL_RAW": "https://gist.githubusercontent.com/claymcleod/b3adc0a5ca47b716dd6b/raw", 90 | "URL_USER": "github.com/claymcleod" 91 | }, 92 | { 93 | "Title": " Sort nuts and bolts", 94 | "Authors": " Clay McLeod", 95 | "Description": " Solving the classic sorting of nuts and bolts problem.", 96 | "Section": " Python", 97 | "Subsection": " Interesting Problems", 98 | "URL": "https://gist.github.com/claymcleod/8db5cd9070c83c27524d/", 99 | "URL_RAW": "https://gist.githubusercontent.com/claymcleod/8db5cd9070c83c27524d/raw", 100 | "URL_USER": "github.com/claymcleod" 101 | }, 102 | { 103 | "Title": " UIDynamics", 104 | "Authors": " Clay McLeod", 105 | "Description": " A brief overview of UIDynamics in iOS 8", 106 | "Section": " Swift", 107 | "Subsection": " UI", 108 | "URL": "https://gist.github.com/claymcleod/2507bc8f582d85a6dd93/", 109 | "URL_RAW": "https://gist.githubusercontent.com/claymcleod/2507bc8f582d85a6dd93/raw", 110 | "URL_USER": "github.com/claymcleod" 111 | } 112 | ] -------------------------------------------------------------------------------- /gc_products/gists.md: -------------------------------------------------------------------------------- 1 | # Objective-C 2 | ### System Events 3 | 4 | ##### Sending Keystrokes 5 | * Authors: Clay McLeod 6 | * Description: An example of how to send keystrokes to a window 7 | * URL: https://gist.github.com/claymcleod/9d0a0a6eda00e8754546/ 8 | * URL_USER: github.com/claymcleod 9 | 10 | # Python 11 | ### Data Science 12 | 13 | ##### Reddit Data Mining Script 14 | * Authors: Clay McLeod 15 | * Description: This script mines JSON data from the Reddit front page and stores it as a CSV file for analysis. 16 | * URL: https://gist.github.com/claymcleod/1613590bbfc8203c0797/ 17 | * URL_USER: github.com/claymcleod 18 | 19 | ### General 20 | 21 | ##### Regular Expressions with Python 22 | * Authors: Clay McLeod 23 | * Description: Shows you how to find all instances of a regular expression in a string 24 | * URL: https://gist.github.com/claymcleod/a30752456fbb5efe8bcf/ 25 | * URL_USER: github.com/claymcleod 26 | 27 | ### Interesting Problems 28 | 29 | ##### Edit Distance 30 | * Authors: Clay McLeod 31 | * Description: Python edit distance problem 32 | * URL: https://gist.github.com/claymcleod/f9ce092cfed501408ee6/ 33 | * URL_USER: github.com/claymcleod 34 | 35 | ##### Max subarray 36 | * Authors: Clay McLeod 37 | * Description: Finds the max subarray of an array of integers, in O(nlogn) time 38 | * URL: https://gist.github.com/claymcleod/26e2f380f4dda468fd56/ 39 | * URL_USER: github.com/claymcleod 40 | 41 | ##### Sort nuts and bolts 42 | * Authors: Clay McLeod 43 | * Description: Solving the classic sorting of nuts and bolts problem. 44 | * URL: https://gist.github.com/claymcleod/8db5cd9070c83c27524d/ 45 | * URL_USER: github.com/claymcleod 46 | 47 | # Ruby 48 | ### Data Science 49 | 50 | ##### Simple Ruby Datamining Example 51 | * Authors: Clay McLeod 52 | * Description: Mines data every minute concerning how many people are logged into a certain subreddit. 53 | * URL: https://gist.github.com/claymcleod/b3adc0a5ca47b716dd6b/ 54 | * URL_USER: github.com/claymcleod 55 | 56 | # Swift 57 | ### General 58 | 59 | ##### Regular Expressions with Swift 60 | * Authors: Clay McLeod 61 | * Description: A brief overview of regular expressions with Swift 62 | * URL: https://gist.github.com/claymcleod/39214f470d71363d6410/ 63 | * URL_USER: github.com/claymcleod 64 | 65 | ### UI 66 | 67 | ##### Listening for Tap Gestures 68 | * Authors: Clay McLeod 69 | * Description: How to handle tap gestures on a view controller. 70 | * URL: https://gist.github.com/claymcleod/b46a1c84e39cddc868e7/ 71 | * URL_USER: github.com/claymcleod 72 | 73 | ##### UIDynamics 74 | * Authors: Clay McLeod 75 | * Description: A brief overview of UIDynamics in iOS 8 76 | * URL: https://gist.github.com/claymcleod/2507bc8f582d85a6dd93/ 77 | * URL_USER: github.com/claymcleod 78 | 79 | ### Variables 80 | 81 | ##### Lazy Initialization of Swift Variables 82 | * Authors: Clay McLeod 83 | * Description: An example of how to create a variable using lazy initialization in the Swift programming language. 84 | * URL: https://gist.github.com/claymcleod/d66f08c06918cee065be/ 85 | * URL_USER: github.com/claymcleod 86 | 87 | -------------------------------------------------------------------------------- /gist-compile.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = 'gist-compile' 3 | s.version = '1.0.1' 4 | s.date = '2015-02-22' 5 | s.summary = "Gist-compile will compile Github gists into an intelligible, book like, form." 6 | s.description = "" 7 | s.authors = ["Clay McLeod"] 8 | s.email = 'clay.l.mcleod@gmail.com' 9 | s.files = `git ls-files`.split($\) 10 | s.executables = ['gist-compile'] 11 | s.require_paths = ["lib"] 12 | s.homepage = 'http://github.com/claymcleod/gist-compile' 13 | s.license = 'MIT' 14 | s.add_runtime_dependency 'thor', '~> 0.19.1', '>= 0.19.1' 15 | s.add_runtime_dependency 'paint', '~> 0.9.0', '>= 0.9' 16 | s.add_runtime_dependency 'nokogiri', '~> 1.6.6', '>= 1.6.6' 17 | s.add_runtime_dependency 'rest-client', '~> 1.7.2', '>= 1.7.2' 18 | end 19 | -------------------------------------------------------------------------------- /lib/json-serializer.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | class JSONSerializer 4 | attr_accessor :json 5 | attr_accessor :linkauthor 6 | 7 | def initialize(json, linkauthor) 8 | @json = json 9 | @linkauthor = linkauthor 10 | end 11 | 12 | def compile 13 | structured_gists = Hash.new{ |h,k| h[k] = Hash.new(&h.default_proc) } 14 | 15 | entries = JSON.parse(json) 16 | entries.each do |arr| 17 | title = arr["Title"] != nil ? arr["Title"].strip() : nil 18 | authors = arr["Authors"] != nil ? arr["Authors"].strip() : nil 19 | description = arr["Description"] != nil ? arr["Description"].strip() : nil 20 | section = arr["Section"] != nil ? arr["Section"].strip() : nil 21 | subsection = arr["Subsection"] != nil ? arr["Subsection"].strip() : nil 22 | url = arr["URL"] != nil ? arr["URL"].strip() : nil 23 | url_user = arr["URL_USER"] != nil ? arr["URL_USER"].strip() : nil 24 | 25 | if title == nil 26 | puts "Error: A title must be included for #{url}" 27 | next 28 | end 29 | 30 | if section == nil || subsection == nil 31 | puts "Error: #{title} must have a section and subsection to be compiled!" 32 | next 33 | end 34 | 35 | structured_gists[section][subsection][title] = {"Authors"=>authors, "Description"=>description, 36 | "URL"=>url, "URL_USER"=>url_user} 37 | end 38 | structured_gists = structured_gists.sort.to_h 39 | structured_gists.keys.each do |k| 40 | structured_gists[k] = structured_gists[k].sort.to_h 41 | structured_gists[k].keys.each do |l| 42 | structured_gists[k][l] = structured_gists[k][l].sort.to_h 43 | end 44 | end 45 | 46 | return structured_gists 47 | end 48 | 49 | def to_md(file) 50 | structured_gists = compile() 51 | File.open(file,"w") do |f| 52 | structured_gists.each do |j, v| 53 | f.puts("# #{j}\r") 54 | structured_gists[j].each do |k, v| 55 | f.puts("### #{k}\r") 56 | f.puts("\r\n") 57 | structured_gists[j][k].each do |t, v| 58 | f.puts("##### #{t}\r") 59 | structured_gists[j][k][t].each do |l, v| 60 | if v != nil 61 | f.puts("* #{l}: #{v}\r") 62 | end 63 | end 64 | f.puts("\r\n") 65 | end 66 | end 67 | end 68 | f.close() 69 | end 70 | end 71 | 72 | def to_html(file) 73 | structured_gists = compile() 74 | File.open(file,"w") do |f| 75 | f.puts("") 76 | f.puts("") 77 | f.puts(" \n \n "); 78 | f.puts(" ") 79 | f.puts(" Generated by gist-compile at "+Time.new.strftime("%Y-%m-%d %H:%M:%S")) 80 | structured_gists.each do |j, v| 81 | f.puts("
\r") 82 | f.puts(" ") 83 | f.puts("

#{j}

\r") 84 | f.puts("
") 85 | structured_gists[j].each do |k, v| 86 | f.puts("

#{k}

\r") 87 | f.puts("\r\n") 88 | structured_gists[j][k].each do |t, v| 89 | url= structured_gists[j][k][t]["URL"] 90 | if url == nil 91 | f.puts("

#{t}

\r") 92 | else 93 | f.puts("

#{t}

") 94 | end 95 | f.puts(" \r") 107 | end 108 | end 109 | end 110 | f.puts(" "); 111 | f.puts(""); 112 | f.close() 113 | end 114 | end 115 | end 116 | --------------------------------------------------------------------------------