dinner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5fbeb0b0678789d34dd454e4103a0350f22c7542
4
+ data.tar.gz: 2c1768e344c5f3969679a2056ddfe76d832fe5ac
5
+ SHA512:
6
+ metadata.gz: 10820ec69a2be7bb2d4a89889dcba41d3d824bf02b3e785a3c31861908af29ebeedcb3d8ba64e7a4f8fc2472e5b823662ae1376b67669e368422acd444faf19b
7
+ data.tar.gz: 478c0cf84c9bef188bf3f0e5f213652335106191e90f1b9bee5050bac68e675e725e5f3357565db750b58ed8c620338e28c48289c771238a4082c9b84eb7fac3
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ test/
12
+ test2/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Dan Turkel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,132 @@
1
+ # Dinner.rb
2
+
3
+ - [What's Dinner?](#what)
4
+ - [Installation](#install)
5
+ - [Usage](#usage)
6
+ - [Example](#example)
7
+ - [Uninstallation](#uninstall)
8
+ - [Contributing](#contribute)
9
+
10
+ ## <a name="what">What's Dinner?</a>
11
+
12
+ Dinner is a Ruby gem designed to replicate some of the feature set of [Hammer](http://hammerformac.com/) for Mac. I'm a huge fan of Hammer's ability to do HTML includes and variables, so I made Dinner to see how well I could do it myself without the app, 'cause why not?
13
+
14
+ Basically, you can write HTML pages with lines like `<!-- @include _header.html -->` and then Dinner will automagically copy your header file into all of your HTML pages, allowing you to edit that header file and see your changes propagate across all your files after running Dinner! This is perfect for building static sites where you don't want to bother with PHP includes but still want to be able to easily edit your templates (or 'plates, hence Dinner, get it?).
15
+
16
+ The project is similar in scope to [grunt-includes](https://github.com/vanetix/grunt-includes) but does not involve setting up [grunt](http://gruntjs.com/) tasks, uses a different syntax, and is Ruby-based rather than JS based.
17
+
18
+ ### What it does so far:
19
+
20
+ - Include `_foo.html` files into `bar.html` files and move the compiled results into a build directory, but only when you manually run the app
21
+ - Makes a `dinconfig.yaml` file where you can:
22
+ - Edit the build folder name
23
+ - More to come
24
+ - Finds placeholder tags and switches them for [placehold.it](http://placehold.it) `img` tags. (See [Example](#example) below)
25
+ - That's basically it
26
+
27
+ ### What I'm going to do for sure
28
+ - Better documentation
29
+ - Support Hammer-style [HTML variables](http://hammerformac.com/docs/tags/variables)
30
+ - Fix behavior with HTML files that are inside directories in the working directory (currently the directory structure will be flattened inside the build folder)
31
+ - Copying CSS and JS files (perhaps more) to the build folder so that loading the build file in a web browser will not result in dead links to stylesheets and scripts which are in the parent directory
32
+ - <del>Make a easy-to-use YAML config file where you can change:</del> done!
33
+ - <del>Edit the build folder name</del> done!
34
+ - what non-HTML files should be copied to the build directory (and if you want them minified)
35
+ - probably more stuff
36
+ - Use the [listen](https://github.com/guard/listen) gem to automatically recompile files when they're edited, so the app doesn't need to be manually run
37
+ - Add rspec tests
38
+ - Put it on RubyGems when it's moderately ready
39
+ - <del>Replicate Hammer's [image placeholders](http://hammerformac.com/docs/tags/placeholder) feature</del> done!
40
+
41
+ ### What maybe I'll do
42
+ - Support includes within includes
43
+ - Support includes that are not in `_foo.html` name format
44
+ - Replicate Hammer's [navigation helpers](http://hammerformac.com/docs/tags/navigation.html) feature
45
+ - Add Sass/SCSS compilation
46
+
47
+ ### What I definitely won't do but feel free to contribute
48
+ - Coffeescript compilation
49
+ - Replicate Hammer's [cache](http://hammerformac.com/docs/cache) feature
50
+
51
+
52
+ ## <a name="install">Installation</a>
53
+
54
+ Dinner isn't on RubyGems yet and is still in early dev stages. If you want to play with it or contribute, go ahead and run
55
+
56
+ git clone https://github.com/daturkel/dinner.rb.git
57
+
58
+ Then `cd` to the cloned directory and run
59
+
60
+ gem build dinner.gemspec
61
+
62
+ followed by
63
+
64
+ gem install *.gem
65
+
66
+ ## <a name="usage">Usage</a>
67
+
68
+ **Warning**: This product is in early alpha and if used improperly, or if I messed something up, could easily trash your files. I recommend you make a backup of your entire working directory or use version control before running `dinner` in your directory (at least at this early stage of development). By using `dinner`, you do so at your own risk.
69
+
70
+ Right now, since Dinner's functionality is fairly limited, this section is quite simple! After installing the gem, simply `cd` to your working directory. If you have not already, you should isolate all your project files into their own directory to avoid accidental compilation of other unrelated files.
71
+
72
+ Write HTML pages into files with typical names (`about.html`) and files that will be included into files that have leading-underscore names (`_header.html`). In your page files (like `about.html`), where you want an include, insert a single line with a comment in this form: `<!-- @include _foo.html -->` (or, alternatively, as `<!-- @include _foo -->`, without the `.html`, Dinner will assume you meant it) where `_foo.html` is the name of your include file. When you run `dinner` in the working directory, Dinner will automatically find the include file and replace the comment with it, verbatim (no changes to indent amount or anything) and output the new page into your `build/` directory. If Dinner is unable to find an include file, it will simply leave the comment in place and alert you with an error message in the terminal.
73
+
74
+ ## <a name="example">Example</a>
75
+ In `about.html`:
76
+
77
+ ```html
78
+ <!DOCTYPE HTML>
79
+ <html lang="en">
80
+ <head>
81
+ <title>About me!</title>
82
+ </head>
83
+
84
+ <body>
85
+ <!-- @include _head.html -->
86
+ <h2>Welcome</h2>
87
+ <!-- @placeholder 300x400 --><!-- @placeholder 400x500 -->
88
+ <p>This site is all about me! Isn't it neato?</p>
89
+ </body>
90
+ </html>
91
+ ```
92
+
93
+ In `_head.html`:
94
+ ```html
95
+ <p>This banner goes across every page of my website and now I can change it on all of them easily!</p>
96
+ <p>That's sick!</p>
97
+ ```
98
+
99
+ And, after Dinner has been run, in `build/about.html`:
100
+ ````html
101
+ <!DOCTYPE HTML>
102
+ <html lang="en">
103
+ <head>
104
+ <title>About me!</title>
105
+ </head>
106
+
107
+ <body>
108
+ <p>This banner goes across every page of my website and now I can change it on all of them easily!</p>
109
+ <p>That's sick!</p>
110
+ <h2>Welcome</h2>
111
+ <img src="http://placehold.it/300x400"><img src="http://placehold.it/400x500">
112
+ <p>This site is all about me! Isn't it neato?</p>
113
+ </body>
114
+ </html>
115
+ ````
116
+
117
+ It's that easy!
118
+
119
+ ## <a name="uninstall">Uninstallation</a>
120
+
121
+ To uninstall dinner, simply run `gem uninstall dinner` and when prompted to remove the executable, answer `y`.
122
+
123
+
124
+ ## <a name="contribute">Contributing</a>
125
+
126
+ Feel free to contribute by filing an issue or submitting a pull request:
127
+
128
+ 1. Fork it
129
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
130
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
131
+ 4. Push to the branch (`git push origin my-new-feature`)
132
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dinner'
4
+
5
+ Dinner.do_everything
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fileutils'
5
+ require 'find'
6
+ require 'listen'
7
+ require 'yaml'
8
+ require 'dinner/version'
9
+ require 'dinner/configmanager'
10
+ require 'dinner/filemanager'
11
+ require 'dinner/htmlmangler'
12
+
13
+ Gem::Specification.new do |spec|
14
+ spec.name = "dinner"
15
+ spec.version = Dinner::VERSION
16
+ spec.authors = ["daturkel"]
17
+ spec.email = ["daturkel@gmail.com"]
18
+ spec.description = %q{Use dinner to automatically include html files!}
19
+ spec.summary = %q{The 'plating engine.}
20
+ spec.homepage = ""
21
+ spec.license = "MIT"
22
+
23
+ spec.files = `git ls-files`.split($/)
24
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.3"
29
+ spec.add_development_dependency "rake"
30
+ end
@@ -0,0 +1,29 @@
1
+ # Dinner is a Ruby gem for HTML includes.
2
+ #
3
+ # Author:: Dan Turkel (mailto:daturkel@gmail.com)
4
+ # Copyright:: Copyright (c) 2014 Dan Turkel
5
+ # License:: MIT License
6
+
7
+ require_relative 'dinner/version'
8
+ require_relative 'dinner/filemanager'
9
+ require_relative 'dinner/htmlmangler'
10
+ require_relative 'dinner/configmanager'
11
+ require 'fileutils'
12
+ require 'find'
13
+ require 'listen'
14
+ require 'yaml'
15
+
16
+ # This module is the primary Dinner namespace used to wrap the functionality of the rest of the app
17
+ module Dinner
18
+
19
+ # Run Dinner
20
+ def self.do_everything
21
+ ConfigManager.init_config
22
+ FileManager.init_build(FileManager.locate_html(true,false))
23
+ HtmlMangler.insert_includes(FileManager.locate_html(false,true))
24
+ HtmlMangler.insert_placeholders(FileManager.locate_html(false,true))
25
+ end
26
+
27
+ end
28
+
29
+ Dinner.do_everything
@@ -0,0 +1,39 @@
1
+ # This class is for creating/accessing a config file with options for Dinner
2
+ class ConfigManager
3
+
4
+ # The defaults for the config file
5
+ DEFAULT = {
6
+ :build_folder => "build",
7
+ :copy_formats => ["js","css"]
8
+ }
9
+
10
+ @@config = {}
11
+
12
+ # Access the configuration hash
13
+ def self.config
14
+ @@config
15
+ end
16
+
17
+ # A getter method for the config defaults
18
+ def self.default
19
+ DEFAULT
20
+ end
21
+
22
+ # Create a config file if there isn't yet one
23
+ def self.init_config
24
+ if File.exists?("#{Dir.pwd}/dinconfig.yaml")
25
+ self.load_config("#{Dir.pwd}/dinconfig.yaml")
26
+ else
27
+ File.open("#{Dir.pwd}/dinconfig.yaml","w+") do |file|
28
+ file.puts(DEFAULT.to_yaml)
29
+ end
30
+ self.load_config("#{Dir.pwd}/dinconfig.yaml")
31
+ end
32
+ end
33
+
34
+ # Load the current config file
35
+ def self.load_config(file_path)
36
+ @@config = YAML.load(File.read(file_path))
37
+ end
38
+ end
39
+
@@ -0,0 +1,53 @@
1
+ # A module for locating files and creating the build folder
2
+ module FileManager
3
+
4
+ # Find the html files and return a hash containing an array of page files (:files) and an array of include files (:includes)
5
+ def self.locate_html(with_includes,in_build = false)
6
+ html = { :files => {}}
7
+ if with_includes
8
+ html[:includes] = {}
9
+ end
10
+ if in_build
11
+ dir = "#{Dir.pwd}/#{ConfigManager.config[:build_folder]}"
12
+ else
13
+ dir = Dir.pwd
14
+ end
15
+ Find.find(dir) do |path|
16
+ if FileTest.directory?(path)
17
+ if (File.basename(path) == ConfigManager.config[:build_folder]) && !in_build
18
+ Find.prune
19
+ else
20
+ next
21
+ end
22
+ else
23
+ if path =~ /.*\/[^_][^\/]*\.html$/
24
+ html[:files][File.basename(path)] = path
25
+ elsif path =~ /.*\/[_][^\/]*\.html$/ and with_includes
26
+ html[:includes][(File.basename(path)[1..-1])] = path
27
+ end
28
+ end
29
+ end
30
+ return html
31
+ end
32
+
33
+ # Create the build folder if it does not exist. If it does exist, prunes it of old files. Then it moves in the unprocessed page-files.
34
+ # @TODO: Split this into two functions, one to create the build folder if it doesn't exist, and one to delete files which will be replaced
35
+ def self.init_build(html)
36
+ if Dir.exists?(ConfigManager.config[:build_folder])
37
+ Find.find("#{Dir.pwd}/#{ConfigManager.config[:build_folder]}") do |path|
38
+ File.delete(path) if File.extname(path) == ".html"
39
+ end
40
+ else
41
+ Dir.mkdir "#{Dir.pwd}/#{ConfigManager.config[:build_folder]}"
42
+ end
43
+ self.push_files(html)
44
+ end
45
+
46
+ def self.push_files(html)
47
+ html[:files].each_value do |path|
48
+ FileUtils.cp(path,"#{Dir.pwd}/#{ConfigManager.config[:build_folder]}")
49
+ end
50
+ end
51
+
52
+ end
53
+
@@ -0,0 +1,75 @@
1
+ # A module for editing the HTML of files being processed with dinner
2
+ module HtmlMangler
3
+
4
+ # Find @include commands in an html document and replace them with the contents of the correct file, or else display an error in the shell and leave the @include command in place
5
+ def self.insert_includes(html)
6
+ a = 0
7
+ html[:files].each_pair do |name,path|
8
+ lines = IO.readlines(path)
9
+ lines.each_with_index do |line,i|
10
+ if line =~ /^\s*<!-- @include.*/
11
+ if File.exists?("#{Dir.pwd}/#{parse_filename(line)}")
12
+ lines[i] = File.read("#{Dir.pwd}/#{parse_filename(line)}")
13
+ a = i
14
+ else
15
+ puts "Error in #{name}, line #{i+1}: #{parse_filename(line)} missing"
16
+ end
17
+ end
18
+ end
19
+ File.open("#{Dir.pwd}/#{ConfigManager.config[:build_folder]}/#{name}","w+") do |file|
20
+ file.puts(lines)
21
+ end
22
+ end
23
+ end
24
+
25
+ # Take a line of an html page file and derive the name of the referenced file from it
26
+ def self.parse_filename(line)
27
+ clean_line = line.dup
28
+ clean_line.slice!("<!-- @include")
29
+ clean_line.slice!("-->")
30
+ clean_line.strip!
31
+ if clean_line.include?(".html")
32
+ return clean_line
33
+ else
34
+ return clean_line + ".html"
35
+ end
36
+ end
37
+
38
+ # Replace variables
39
+ def self.insert_variables(html)
40
+ a = 0
41
+ html[:files].each_pair do |name,path|
42
+ lines = IO.readlines(path)
43
+ lines.each_with_index do |line,i|
44
+ if line =~ /^\s*<!-- \$.*/
45
+ # @TODO figure out how best to pick out those variable names
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ # Auto-insert placeholder images
52
+ def self.insert_placeholders(html)
53
+ html[:files].each_pair do |name,path|
54
+ lines = IO.readlines(path)
55
+ lines.each_with_index do |line,i|
56
+ while line =~ /.*<!-- @placeholder.*/
57
+ info = parse_placeholder(line.match(/<!--[^>]*?-->/)[0])
58
+ line = line.sub(/<!--[^>]*?-->/,"<img src=\"http://placehold.it/#{info[:res]}\">")
59
+ lines[i] = line
60
+ end
61
+ end
62
+ File.open("#{Dir.pwd}/#{ConfigManager.config[:build_folder]}/#{name}","w+") do |file|
63
+ file.puts(lines)
64
+ end
65
+ end
66
+ end
67
+
68
+ def self.parse_placeholder(line)
69
+ info = {}
70
+ info[:res] = line.match(/\d*x\d*/)[0]
71
+ info
72
+ end
73
+
74
+ end
75
+
@@ -0,0 +1,5 @@
1
+ # A module containing the current version number of Dinner
2
+ module Dinner
3
+ VERSION = "0.1.0"
4
+ end
5
+
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dinner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - daturkel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Use dinner to automatically include html files!
42
+ email:
43
+ - daturkel@gmail.com
44
+ executables:
45
+ - dinner
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/dinner
55
+ - dinner.gemspec
56
+ - lib/dinner.rb
57
+ - lib/dinner/configmanager.rb
58
+ - lib/dinner/filemanager.rb
59
+ - lib/dinner/htmlmangler.rb
60
+ - lib/dinner/version.rb
61
+ homepage: ''
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: The 'plating engine.
85
+ test_files: []