jekyll-foundation-building-blocks 0.0.1

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: 923b36c3b075348dc68179227011566acba0343f
4
+ data.tar.gz: 199c4f7b1f399cb502034078023afd334049ddac
5
+ SHA512:
6
+ metadata.gz: 45aca5612423eb9577a8b9590a64dd75ba3d0ab12111beda1ae75e0a8577e5d48a6b3fa504ef0ed4a2d4e9e76e2bd6845275827213c76c6a286ca9ad4285f2de
7
+ data.tar.gz: a3d9822702aeb59e46e9dcdcfdff51fb9fd3f6635ef8c1404f47a9dc48d30dc4696df743d0df2a7571967d71459e403c7c12bdd308ff8a6bf5ff76e9a947dc24
@@ -0,0 +1,6 @@
1
+ $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
2
+ require 'rubygems'
3
+ require 'jekyll'
4
+ require 'jekyll-foundation-building-blocks/blocks'
5
+
6
+ require 'jekyll/commands'
@@ -0,0 +1,51 @@
1
+ require 'jekyll-foundation-building-blocks/util'
2
+ require 'colorator'
3
+ require 'fileutils'
4
+
5
+ module JekyllFoundationBuildingBlocks
6
+ BLOCKS_ROOT = "https://foundation.zurb.com/building-blocks/"
7
+ BLOCKS_FILE_ROOT = "#{BLOCKS_ROOT}/files/building-blocks/"
8
+ BLOCKS_JSON_URL = "#{BLOCKS_ROOT}data/building-blocks.json"
9
+ module Blocks
10
+ def self.list
11
+ Util.fetch_json(BLOCKS_JSON_URL).each_with_index do |pair, i|
12
+ key = pair[0]
13
+ value = pair[1]
14
+ Jekyll.logger.info "#{i})".green + " #{key}".cyan + ":#{value['name']}"
15
+ end
16
+ end
17
+
18
+ def self.install(key)
19
+ self._install_partial(key)
20
+ self._install_scss(key)
21
+ self._install_js(key)
22
+ Jekyll.logger.info("installed #{key}")
23
+ # TODO: Any sort of auto-inclusion we want to set up
24
+ end
25
+
26
+ def self._install_partial(key)
27
+ file = Util.fetch_url("#{BLOCKS_FILE_ROOT}#{key}/#{key}.html")
28
+ dir = File.join("_includes", "building-blocks")
29
+ FileUtils.mkdir_p(dir)
30
+ filename = "#{key}.html"
31
+ File.open(File.join(dir, filename), 'w').write(file)
32
+ end
33
+
34
+ def self._install_scss(key)
35
+ file = Util.fetch_url("#{BLOCKS_FILE_ROOT}#{key}/#{key}.scss")
36
+ return unless file.size > 0
37
+ dir = File.join("_sass", "components", "building-blocks")
38
+ FileUtils.mkdir_p(dir)
39
+ File.open(File.join(dir, "_#{key}.scss"), 'w').write(file)
40
+ end
41
+
42
+ def self._install_js(key)
43
+ file = Util.fetch_url("#{BLOCKS_FILE_ROOT}#{key}/#{key}.js")
44
+ return unless file.size > 0
45
+ dir = File.join("js", "building-blocks")
46
+ FileUtils.mkdir_p(dir)
47
+ File.open(File.join(dir, "#{key}.js"), 'w').write(file)
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,31 @@
1
+ require 'jekyll-foundation-building-blocks/util'
2
+ require 'colorator'
3
+ require 'jekyll-foundation-building-blocks/blocks'
4
+
5
+ module JekyllFoundationBuildingBlocks
6
+ KITS_JSON_URL = "#{BLOCKS_ROOT}data/kits.json"
7
+
8
+ module Kits
9
+ def self.list
10
+ Util.fetch_json(KITS_JSON_URL).each_with_index do |pair, i|
11
+ key = pair[0]
12
+ value = pair[1]
13
+ Jekyll.logger.info "#{i})".green + " #{key}".cyan + ": #{value['total']} blocks"
14
+ end
15
+ end
16
+
17
+ def self.install(key)
18
+ kits = Util.fetch_json(KITS_JSON_URL)
19
+ unless kits[key]
20
+ Jekyll.logger.error "Could not find kit #{kit}"
21
+ return 1
22
+ end
23
+
24
+ kits[key]['blocks'].each do |block|
25
+ JekyllFoundationBuildingBlocks::Blocks.install(block['datakey'])
26
+ end
27
+
28
+ Jekyll.logger.info("installed kit: #{key}")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ require 'net/http'
2
+
3
+ module JekyllFoundationBuildingBlocks
4
+ module Util
5
+ def self.fetch_url(url)
6
+ uri = URI(url)
7
+ response = Net::HTTP.get_response(uri)
8
+ if response.code == "200"
9
+ response.body
10
+ else
11
+ ''
12
+ end
13
+ end
14
+
15
+ def self.fetch_json(url)
16
+ JSON.parse(self.fetch_url(url))
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ $:.unshift File.expand_path("../../", File.dirname(__FILE__)) # load from jekyll-foundation-building-blocks/lib
2
+ require 'jekyll-foundation-building-blocks/blocks'
3
+ require 'jekyll-foundation-building-blocks/kits'
4
+ module Jekyll
5
+ module Commands
6
+ class FoundationBuildingBlocks < Command
7
+ class << self
8
+ def init_with_program(prog)
9
+ prog.command(:blocks) do |c|
10
+ c.syntax "blocks <SUBCOMMAND> "
11
+ c.description "List and install Foundation Building Blocks"
12
+ c.command(:list) do |sub|
13
+ sub.syntax "blocks list"
14
+ sub.description "List available Foundation Building Blocks"
15
+ sub.action do |args, options|
16
+ JekyllFoundationBuildingBlocks::Blocks.list
17
+ end
18
+ end
19
+ c.command(:install) do |sub|
20
+ sub.syntax "blocks install BLOCK_NAME"
21
+ sub.description "Install Foundation Building Blocks"
22
+ sub.action do |args, options|
23
+ JekyllFoundationBuildingBlocks::Blocks.install(args[0])
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ class FoundationKits < Command
32
+ class << self
33
+ def init_with_program(prog)
34
+ prog.command(:kits) do |c|
35
+ c.syntax "kits <SUBCOMMAND> "
36
+ c.description "List and install Foundation Kits"
37
+ c.command(:list) do |sub|
38
+ sub.syntax "kits list"
39
+ sub.description "List available Foundation Kits"
40
+ sub.action do |args, options|
41
+ JekyllFoundationBuildingBlocks::Kits.list
42
+ end
43
+ end
44
+ c.command(:install) do |sub|
45
+ sub.syntax "kits install KIT_NAME"
46
+ sub.description "Install Foundation Kits"
47
+ sub.action do |args, options|
48
+ JekyllFoundationBuildingBlocks::Kits.install(args[0])
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-foundation-building-blocks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Ball
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ description:
42
+ email:
43
+ - kmball11@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/jekyll-foundation-building-blocks.rb
49
+ - lib/jekyll-foundation-building-blocks/blocks.rb
50
+ - lib/jekyll-foundation-building-blocks/kits.rb
51
+ - lib/jekyll-foundation-building-blocks/util.rb
52
+ - lib/jekyll/commands.rb
53
+ homepage: https://github.com/kball/jekyll-foundation-building-blocks
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.4.8
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Add jekyll command for installing Foundation building blocks and kits
77
+ test_files: []