estatic 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +126 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/estatic.gemspec +30 -0
- data/exe/estatic +23 -0
- data/lib/estatic.rb +57 -0
- data/lib/estatic/category.rb +32 -0
- data/lib/estatic/configuration.rb +25 -0
- data/lib/estatic/csv_parser.rb +11 -0
- data/lib/estatic/generator.rb +84 -0
- data/lib/estatic/home_page.rb +14 -0
- data/lib/estatic/page.rb +23 -0
- data/lib/estatic/page_generator.rb +20 -0
- data/lib/estatic/product_listings_page.rb +21 -0
- data/lib/estatic/product_page.rb +14 -0
- data/lib/estatic/resource.rb +44 -0
- data/lib/estatic/subcategory.rb +28 -0
- data/lib/estatic/version.rb +3 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45c545a97e7970defbe646a3cc775ba994f12f52
|
4
|
+
data.tar.gz: 75e2ddc07bd702cf7daee6f504e4227b18e65235
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e71ed172115caa3b275aa0c260f0ff6ff5d4e8e456745f969a8cd5b143b61f6252b1f871d8f45183772fded35ca9786961905ca1e09218cada2369d106c03d2c
|
7
|
+
data.tar.gz: 45aec7f7a5aa94158eb19cd234b176128f7558337c3c2b0db94bc89267bde42f74f7d3b2d5f243c2ebe925155ff6e7c6e1cfb9ae0b98bd57af435addce7dad96
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Karlo Escota
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# Estatic
|
2
|
+
|
3
|
+
Estatic (E-commerce Static) is a static e-commerce site generator. This gem dynamically adds products from csv files to your (erb, slim, haml) templates and generates static html pages. The current templates supported are for the `home_page`, `product_listings_page`, and `product_page`.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install estatic
|
8
|
+
|
9
|
+
## Setup
|
10
|
+
|
11
|
+
Go to your working directory
|
12
|
+
|
13
|
+
$ cd /path/to/working/directory
|
14
|
+
|
15
|
+
The working directory must have a `blueprints` folder which may contain the following:
|
16
|
+
- `csv` folder for category/subcategory products
|
17
|
+
- `shared` folder for template partials
|
18
|
+
- `css` folder
|
19
|
+
- `scripts` folder
|
20
|
+
- `config.yml`
|
21
|
+
- `home_page.(erb,slim,haml)`
|
22
|
+
- `product_listings_page.(erb,slim,haml)` for your category/subcategory product listings
|
23
|
+
- `product_page.(erb,slim,haml)` for individual product page
|
24
|
+
- `additional` folder/s. this will be copied to your static site
|
25
|
+
|
26
|
+
files and folders are all optional depending on the requirements of your estatic site
|
27
|
+
|
28
|
+
---
|
29
|
+
|
30
|
+
A sample working directory structure
|
31
|
+
|
32
|
+
```
|
33
|
+
+-- working_directory
|
34
|
+
+-- blueprints
|
35
|
+
+-- csv
|
36
|
+
| +-- featured.csv
|
37
|
+
| +-- category_sample.csv
|
38
|
+
| +-- subcat_1.csv
|
39
|
+
| +-- subcat_2.csv
|
40
|
+
+-- shared
|
41
|
+
| +-- partial.erb
|
42
|
+
+-- css
|
43
|
+
| +-- app.css
|
44
|
+
+-- scripts
|
45
|
+
| +-- app.js
|
46
|
+
+-- optional-folder-of-other-stuff-goes-here
|
47
|
+
| +-- other-stuff.png
|
48
|
+
+-- optional-folder-of-another-stuff-goes-here
|
49
|
+
| +-- another-stuff.ttf
|
50
|
+
+-- config.yml
|
51
|
+
+-- home_page.erb
|
52
|
+
+-- product_listings_page.erb
|
53
|
+
+-- product_page.erb
|
54
|
+
```
|
55
|
+
|
56
|
+
## Configuration
|
57
|
+
|
58
|
+
In your `config.yml`
|
59
|
+
|
60
|
+
```
|
61
|
+
featured: featured # translate featured.csv as home_page products
|
62
|
+
categories:
|
63
|
+
- category_sample # translate category_sample.csv as category products
|
64
|
+
- category_with_subcategory: # translate subcat_1.csv and subcat_2.csv as category products
|
65
|
+
- subcat_1 # translate subcat_1.csv as subcategory products
|
66
|
+
- subcat_2 # translate subcat_2.csv as subcategory products
|
67
|
+
chunk: 20 # maximum number of products per product_listings_page
|
68
|
+
include_product_page: true # flag to generate product_page, default is false
|
69
|
+
```
|
70
|
+
|
71
|
+
category and subcategory products are rendered in `product_listings_page`
|
72
|
+
|
73
|
+
## Manage Templates
|
74
|
+
|
75
|
+
There are instance variables you can use depending on which template:
|
76
|
+
|
77
|
+
---
|
78
|
+
__home_page.erb__, __product_listings_page.erb__
|
79
|
+
- `@resource` - category/subcategory
|
80
|
+
- `.name`
|
81
|
+
- `.products` - array of products (all)
|
82
|
+
- `.subcategories` - array of subcategory resource objects. only applicable if `@resource` is a category
|
83
|
+
- `@products` - array of products per chunk (current chunk per page). for product_listings_page only.
|
84
|
+
- an element of `@products` array has an `.attribute_name` depending on the csv header
|
85
|
+
- `@current_page`
|
86
|
+
- `@total_pages`
|
87
|
+
|
88
|
+
---
|
89
|
+
__product_page.erb__
|
90
|
+
- `@resource` - category/subcategory
|
91
|
+
- same as above
|
92
|
+
- `@product`
|
93
|
+
- `.attribute_name` - depends on the csv header
|
94
|
+
|
95
|
+
---
|
96
|
+
|
97
|
+
## Usage
|
98
|
+
|
99
|
+
Inside your working directory
|
100
|
+
|
101
|
+
$ estatic
|
102
|
+
|
103
|
+
It will then generate an `estatic_site` folder
|
104
|
+
|
105
|
+
$ cd estatic_site
|
106
|
+
|
107
|
+
You can now open your generated static pages on your browser
|
108
|
+
|
109
|
+
## Development
|
110
|
+
|
111
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests or you can run guard `bundle exec guard`. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
112
|
+
|
113
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
114
|
+
|
115
|
+
## Contributing
|
116
|
+
|
117
|
+
Fork the repo.
|
118
|
+
|
119
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/karloescota/estatic.
|
120
|
+
|
121
|
+
|
122
|
+
## License
|
123
|
+
|
124
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
125
|
+
|
126
|
+
(c) Karlo Escota
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "estatic"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/estatic.gemspec
ADDED
@@ -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 'estatic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "estatic"
|
8
|
+
spec.version = Estatic::VERSION
|
9
|
+
spec.authors = ["Karlo Escota"]
|
10
|
+
spec.email = ["karlo.escota@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ecommerce Static site generator}
|
13
|
+
spec.description = %q{Dynamically add products using csv to an erb, slim, or haml template
|
14
|
+
to generate static pages}
|
15
|
+
spec.homepage = "https://github.com/karloescota/estatic"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = ["estatic"]
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
27
|
+
spec.add_development_dependency "tilt", "~> 2.0"
|
28
|
+
spec.add_development_dependency "haml", "~> 4.0"
|
29
|
+
spec.add_development_dependency "slim", "~> 3.0"
|
30
|
+
end
|
data/exe/estatic
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'estatic'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
config_file = 'blueprints/config.yml'
|
7
|
+
|
8
|
+
if Dir.glob(config_file).any?
|
9
|
+
puts 'Initializing configuration...'
|
10
|
+
configuration = YAML.load_file(config_file)
|
11
|
+
Estatic.configure do |config|
|
12
|
+
configuration.each do |k, v|
|
13
|
+
config.send("#{k}=", v)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
else
|
17
|
+
puts 'Initializing default configuration...'
|
18
|
+
end
|
19
|
+
|
20
|
+
puts 'Generating estatic site...'
|
21
|
+
Estatic.generate
|
22
|
+
|
23
|
+
puts 'Done.'
|
data/lib/estatic.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'estatic/version'
|
2
|
+
require 'estatic/generator'
|
3
|
+
require 'estatic/configuration'
|
4
|
+
require 'estatic/resource'
|
5
|
+
require 'estatic/category'
|
6
|
+
require 'estatic/subcategory'
|
7
|
+
require 'estatic/page_generator'
|
8
|
+
require 'estatic/page'
|
9
|
+
require 'estatic/product_listings_page'
|
10
|
+
require 'estatic/product_page'
|
11
|
+
require 'estatic/home_page'
|
12
|
+
require 'estatic/csv_parser'
|
13
|
+
require 'tilt'
|
14
|
+
require 'haml'
|
15
|
+
require 'slim'
|
16
|
+
require 'csv'
|
17
|
+
require 'ostruct'
|
18
|
+
require 'json'
|
19
|
+
require 'fileutils'
|
20
|
+
require 'logger'
|
21
|
+
|
22
|
+
module Estatic
|
23
|
+
module_function
|
24
|
+
|
25
|
+
def root
|
26
|
+
File.dirname __dir__
|
27
|
+
end
|
28
|
+
|
29
|
+
def logger
|
30
|
+
@logger ||= Logger.new(STDOUT).tap do |logger|
|
31
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
32
|
+
"#{severity + ': ' if severity == 'ERROR'}#{msg}\n"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def configure
|
38
|
+
yield configuration
|
39
|
+
end
|
40
|
+
|
41
|
+
def configuration
|
42
|
+
@configuration ||= Configuration.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate
|
46
|
+
generator = Generator.new
|
47
|
+
generator.run
|
48
|
+
end
|
49
|
+
|
50
|
+
def csv_files
|
51
|
+
@csv_files ||= Dir.glob("#{Estatic.configuration.project_path}/blueprints/csv/*.csv")
|
52
|
+
end
|
53
|
+
|
54
|
+
def templates
|
55
|
+
@templates ||= Dir.glob("#{Estatic.configuration.project_path}/blueprints/*.{erb,haml,slim}")
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Estatic
|
2
|
+
class Category < Resource
|
3
|
+
attr_accessor :subcategories, :products
|
4
|
+
|
5
|
+
def initialize(name, subcategories = [])
|
6
|
+
super(name)
|
7
|
+
@subcategories = subcategories.map { |subcategory| Subcategory.new(subcategory, name) }
|
8
|
+
@products = get_products
|
9
|
+
end
|
10
|
+
|
11
|
+
def has_subcategories?
|
12
|
+
subcategories.any?
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_products
|
16
|
+
if has_subcategories?
|
17
|
+
subcategories.map(&:products).flatten
|
18
|
+
else
|
19
|
+
products = CSVParser.parse(name)
|
20
|
+
products.map { |attributes| OpenStruct.new product(attributes) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def directory
|
25
|
+
File.join(Estatic.configuration.estatic_site_path, name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def root_path
|
29
|
+
'../'.freeze
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Estatic
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :chunk,
|
4
|
+
:title,
|
5
|
+
:project_path,
|
6
|
+
:estatic_site_path,
|
7
|
+
:categories,
|
8
|
+
:featured,
|
9
|
+
:include_product_page,
|
10
|
+
:domain,
|
11
|
+
:locals
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@chunk = 8
|
15
|
+
@title = 'Estatic'
|
16
|
+
@project_path = Dir.pwd
|
17
|
+
@estatic_site_path = File.join(Dir.pwd, 'estatic_site')
|
18
|
+
@categories = []
|
19
|
+
@featured = nil
|
20
|
+
@include_product_page = false
|
21
|
+
@domain = @estatic_site_path
|
22
|
+
@locals = []
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Estatic
|
2
|
+
class CSVParser
|
3
|
+
OPTIONS = { headers: true, converters: :all, encoding: 'UTF-8' }
|
4
|
+
|
5
|
+
def self.parse(resource)
|
6
|
+
csv = Estatic.csv_files.detect { |file| File.basename(file, '.csv') == resource }
|
7
|
+
parsed = csv ? CSV.read(csv, OPTIONS).map(&:to_h) : []
|
8
|
+
parsed
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Estatic
|
2
|
+
class Generator
|
3
|
+
def initialize
|
4
|
+
site_path = "#{Dir.pwd}/estatic_site".freeze
|
5
|
+
|
6
|
+
unless File.directory?(site_path)
|
7
|
+
FileUtils.mkdir_p site_path
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
generate_home_page if config.featured
|
13
|
+
|
14
|
+
config.categories.each do |config_category|
|
15
|
+
category = fetch_category(config_category)
|
16
|
+
generate_product_listings_pages(category)
|
17
|
+
|
18
|
+
unless category.has_subcategories?
|
19
|
+
generate_product_pages(category) if config.include_product_page
|
20
|
+
else
|
21
|
+
category.subcategories.each do |subcategory|
|
22
|
+
generate_product_listings_pages(subcategory)
|
23
|
+
generate_product_pages(subcategory) if config.include_product_page
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
copy_assets_folder
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def config
|
34
|
+
@config ||= Estatic.configuration
|
35
|
+
end
|
36
|
+
|
37
|
+
def fetch_category(category)
|
38
|
+
if category.is_a? Hash
|
39
|
+
category_name = category.keys.first.to_s
|
40
|
+
subcategories = category.values.first
|
41
|
+
Category.new(category_name, subcategories)
|
42
|
+
else
|
43
|
+
Category.new(category)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def copy_assets_folder
|
48
|
+
assets.each do |asset|
|
49
|
+
asset_folder = "#{config.project_path}/blueprints/#{asset}/"
|
50
|
+
FileUtils.cp_r asset_folder, "#{config.estatic_site_path}/#{asset}" if Dir.glob(asset_folder).any?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def assets
|
55
|
+
Dir.chdir('blueprints') do
|
56
|
+
Dir.glob('*').select { |f| File.directory?(f) && !%w(csv shared).include?(f) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate_home_page
|
61
|
+
Estatic.logger.info 'Generating home page'
|
62
|
+
featured = Category.new(config.featured)
|
63
|
+
home_page = HomePage.new(featured)
|
64
|
+
PageGenerator.new(home_page, config.estatic_site_path).generate
|
65
|
+
end
|
66
|
+
|
67
|
+
def generate_product_listings_pages(resource)
|
68
|
+
Estatic.logger.info "Generating `#{resource.proper_name}`"
|
69
|
+
(1..resource.total_chunks).each do |page_number|
|
70
|
+
product_listings_page = ProductListingsPage.new(resource, page_number)
|
71
|
+
Estatic.logger.info "- page #{page_number}"
|
72
|
+
PageGenerator.new(product_listings_page, resource.directory).generate
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def generate_product_pages(resource)
|
77
|
+
resource.products.each do |product|
|
78
|
+
product_page = ProductPage.new(resource, product)
|
79
|
+
Estatic.logger.info "Generating `#{product.name}` page"
|
80
|
+
PageGenerator.new(product_page, resource.directory).generate
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/estatic/page.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Estatic
|
2
|
+
class Page
|
3
|
+
attr_accessor :resource
|
4
|
+
|
5
|
+
def initialize(resource)
|
6
|
+
@resource = resource
|
7
|
+
end
|
8
|
+
|
9
|
+
def content
|
10
|
+
Tilt.new(template).render(self, resource.locals)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def template
|
16
|
+
Estatic.templates.detect { |file| File.basename(file, '.*') == class_name }
|
17
|
+
end
|
18
|
+
|
19
|
+
def class_name
|
20
|
+
self.class.name.split('::').last.gsub(/(.)([A-Z](?=[a-z]))/,'\1_\2').downcase
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Estatic
|
2
|
+
class PageGenerator
|
3
|
+
attr_reader :page, :directory
|
4
|
+
|
5
|
+
def initialize(page, directory)
|
6
|
+
@page = page
|
7
|
+
@directory = directory
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate
|
11
|
+
FileUtils.mkdir_p(directory) unless File.directory?(directory)
|
12
|
+
|
13
|
+
Dir.chdir(directory) do
|
14
|
+
File.open(page.filename, 'w') do |f|
|
15
|
+
f.write(page.content)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Estatic
|
2
|
+
class ProductListingsPage < Page
|
3
|
+
attr_reader :products, :current_page, :total_pages
|
4
|
+
|
5
|
+
def initialize(resource, page_number)
|
6
|
+
super(resource)
|
7
|
+
@products = resource.products_in_chunks[page_number - 1]
|
8
|
+
@current_page = page_number
|
9
|
+
@total_pages = resource.total_chunks
|
10
|
+
end
|
11
|
+
|
12
|
+
def filename
|
13
|
+
current_page == 1 ? 'index.html' : "#{current_page}.html"
|
14
|
+
end
|
15
|
+
|
16
|
+
def render(filename, args = {})
|
17
|
+
partial = Dir.glob("#{Estatic.configuration.project_path}/blueprints/shared/#{filename}.{erb,haml,slim}").first
|
18
|
+
Tilt.new(partial).render(nil, args[:locals])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Estatic
|
2
|
+
class ProductPage < Page
|
3
|
+
attr_reader :product
|
4
|
+
|
5
|
+
def initialize(resource, product)
|
6
|
+
super(resource)
|
7
|
+
@product = product
|
8
|
+
end
|
9
|
+
|
10
|
+
def filename
|
11
|
+
"#{product.name.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')}.html"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Estatic
|
2
|
+
class Resource
|
3
|
+
attr_accessor :name, :locals
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
@locals = get_locals
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_locals
|
11
|
+
locals = Estatic.configuration.locals.detect { |e| e.keys.first == name }&.values&.first || []
|
12
|
+
locals.map { |local| [local.keys.first, local.values.first] }.to_h
|
13
|
+
end
|
14
|
+
|
15
|
+
def products_in_chunks
|
16
|
+
@chunks ||= products.each_slice(Estatic.configuration.chunk).to_a
|
17
|
+
end
|
18
|
+
|
19
|
+
def total_chunks
|
20
|
+
products_in_chunks.size
|
21
|
+
end
|
22
|
+
|
23
|
+
def directory
|
24
|
+
File.join(Estatic.configuration.estatic_site_path, name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def proper_name
|
28
|
+
name.gsub('-', ' ').split.map(&:capitalize).join(' ')
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def product(attributes)
|
34
|
+
product = attributes.map do |key, value|
|
35
|
+
if key.start_with? 'json_'
|
36
|
+
[key.sub('json_', ''), JSON.parse(value)]
|
37
|
+
else
|
38
|
+
[key, value]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
product.to_h
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Estatic
|
2
|
+
class Subcategory < Resource
|
3
|
+
attr_reader :category_name, :products
|
4
|
+
|
5
|
+
def initialize(name, category_name)
|
6
|
+
super(name)
|
7
|
+
@category_name = category_name
|
8
|
+
@products = get_products
|
9
|
+
end
|
10
|
+
|
11
|
+
def has_subcategories?
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_products
|
16
|
+
products = CSVParser.parse(name)
|
17
|
+
products.map { |attributes| OpenStruct.new product(attributes) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def directory
|
21
|
+
File.join(Estatic.configuration.estatic_site_path, category_name, name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def root_path
|
25
|
+
'../../'.freeze
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: estatic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Karlo Escota
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-21 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tilt
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: haml
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: slim
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
description: |-
|
112
|
+
Dynamically add products using csv to an erb, slim, or haml template
|
113
|
+
to generate static pages
|
114
|
+
email:
|
115
|
+
- karlo.escota@gmail.com
|
116
|
+
executables:
|
117
|
+
- estatic
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- ".gitignore"
|
122
|
+
- ".rspec"
|
123
|
+
- ".travis.yml"
|
124
|
+
- Gemfile
|
125
|
+
- Guardfile
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- estatic.gemspec
|
132
|
+
- exe/estatic
|
133
|
+
- lib/estatic.rb
|
134
|
+
- lib/estatic/category.rb
|
135
|
+
- lib/estatic/configuration.rb
|
136
|
+
- lib/estatic/csv_parser.rb
|
137
|
+
- lib/estatic/generator.rb
|
138
|
+
- lib/estatic/home_page.rb
|
139
|
+
- lib/estatic/page.rb
|
140
|
+
- lib/estatic/page_generator.rb
|
141
|
+
- lib/estatic/product_listings_page.rb
|
142
|
+
- lib/estatic/product_page.rb
|
143
|
+
- lib/estatic/resource.rb
|
144
|
+
- lib/estatic/subcategory.rb
|
145
|
+
- lib/estatic/version.rb
|
146
|
+
homepage: https://github.com/karloescota/estatic
|
147
|
+
licenses:
|
148
|
+
- MIT
|
149
|
+
metadata: {}
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 2.5.1
|
167
|
+
signing_key:
|
168
|
+
specification_version: 4
|
169
|
+
summary: Ecommerce Static site generator
|
170
|
+
test_files: []
|
171
|
+
has_rdoc:
|