cakery 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 581bc71e2bc8d88cbebe64fb5278b4be32436e1e
4
- data.tar.gz: 2a58a2df3fef396a0030863dc0697e5caf405056
3
+ metadata.gz: 920eb92b0f7768c0d57447338be4e816161705f7
4
+ data.tar.gz: 7735938903fb130741577a233d059a32b4054f3c
5
5
  SHA512:
6
- metadata.gz: 28ba82fdd2cd990f583fec317e58732a0bed18af580a63c81bfff43b182803e1477b811bad53d3f9e3c4a0afeeba1f7d1dc722ba8e41b5e0acb7771494406daa
7
- data.tar.gz: 843d171919add9d53ce542d0f3cc6eeb819ecfe36face3d6365069c515ced3456b21ecb2980ecd753d2057f1dbf2be770983fbee60e0c7133a37c72bcfd5e2b0
6
+ metadata.gz: dc687ce06115f77998d5d844febccdc3eb5a740d4945fe4a46301c1f991c11a45dfce137fc61097d32f6797abc7bb335c86eee052c5ba65ad86189b84ce66dcd
7
+ data.tar.gz: 04ccf69a6d5d9d5548c4b38a46e1cf8b02b62cf2d8bc5011fd39fcf23e4e18a4096c166c4aeb652978abd5ae2f43c95891bae3124a3f301ca93692547803dd82
data/README.md CHANGED
@@ -5,31 +5,99 @@
5
5
  [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/sotownsend/cakery/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
6
6
  [![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/sotownsend/cakery/blob/master/LICENSE)
7
7
 
8
- # What is this?
8
+ ##What is this?
9
9
 
10
- cakery helps you with file path issues; never worry again about relative paths with cakery's helper methods.
11
- Purpose built for our continuous integration & deployment infrastructure at Fittr®.
10
+ Combine many files into one intelligently. Cakery has a simple *DSL* that allows you to glob directories and pass strings to an **erb** file. You can also add **macros** to a cakery pipeline. Think about it as a more generic version of [Sprockets](https://github.com/sstephenson/sprockets).
12
11
 
13
- ## File, pwd, and project relative
14
- There are 3 relative ways of looking at a path in *cakery*.
15
- * File Relative - A path relative to the current code file
16
- * pwd Relative - A path relative to the current `pwd` pointer
17
- * project Relative - A path relative to a project root (think rails)
12
+ ## Quick Start
18
13
 
19
- ## Usage
20
- cakery's path helpers work by re-opening the string class to include a set of helper methods. Various
21
- other methods are put into the global object space.
14
+ ###Combine many js files in the `./spec` directory into one file
15
+ In your ruby code:
16
+ ```ruby
17
+ #Create a new recipe
18
+ recipe = Cakery.new('test.js.erb') do |r|
19
+ #The << operator means to glob the directory into a string in @spec
20
+ r.spec << "./spec/*_spec.js"
21
+
22
+ #The < operator means assignment
23
+ r.debug < true
24
+ r.foo < "bar"
25
+ end
26
+
27
+ #Build using the current directory
28
+ cake = recipe.bake
29
+
30
+ #Get the concatenated result of the build
31
+ puts cake.src
32
+ ```
22
33
 
23
- ## String Extension Methods
24
- * `fr` (File relative) - Returns an absolute path from the relative string given assuming the current file is the origin.
25
- * `pr(file)` (Project relative) - Returns an absolute path from the relative string given assuming the first ancestor folder containing `file` is the origin
34
+ Create a test.js.erb with:
35
+ ```erb
36
+ <%= @spec %>
37
+
38
+ <!-- Announce whether we are in debug or release -->
39
+ <% if @debug %>
40
+ console.log("Debug!");
41
+ <% end %>
42
+ console.log("Release :(");
43
+ <% end %>
44
+ ```
26
45
 
27
- ##
46
+ ------
28
47
 
29
- ### Examples
48
+ ###Macros
49
+ Macros receive a block of text and then do something with that text. A *macro* is a subclass of **Cakery::Macro** that implements **def process(str)** and returns a **String**. You can also stack macros.
50
+
51
+ In your ruby code:
30
52
  ```ruby
31
- #Open a file in the same directory as the first anscestor containing a .git file
53
+ #Create a new recipe
54
+ class MyMacro < Cakery::Macro
55
+ def process str
56
+ out = ""
57
+ str.split("\n").each do |line|
58
+ if line =~ /hello/
59
+ out += line.gsub(/hello/, "goodbye")
60
+ else
61
+ out += line
62
+ end
63
+ out += "\n"
64
+ end
65
+ out
66
+ end
67
+ end
68
+
69
+ recipe = Cakery.new('test.js.erb') do |r|
70
+ #The << operator means to glob the directory into a string in @spec
71
+ r.spec << MyMacro << "./spec/*_spec.js"
72
+ r.spec << MyMacro < "hello"
73
+
74
+ #Additionally, you can stack macros. Macros always use the << operator intra macros
75
+ #The last operator may either be < or <<
76
+ r.spec << MyMacro << MyOtherMacro < "Hello"
77
+ r.spec << MyMacro << MyOtherMacro << "./spec/*_spec.js"
78
+
79
+ #The < operator means assignment
80
+ r.debug < true
81
+ r.foo < "bar"
82
+ end
83
+
84
+ #Build using the current directory
85
+ cake = recipe.bake
86
+
87
+ #Get the concatenated result of the build
88
+ puts cake.src
89
+ ```
90
+
91
+ Create a test.js.erb with:
92
+ ```erb
93
+ <%= @spec %>
32
94
 
95
+ <!-- Announce whether we are in debug or release -->
96
+ <% if @debug %>
97
+ console.log("Debug!");
98
+ <% end %>
99
+ console.log("Release :(");
100
+ <% end %>
33
101
  ```
34
102
 
35
103
  ## Requirements
data/Rakefile CHANGED
@@ -1,17 +1,17 @@
1
1
  require 'rspec/core/rake_task'
2
2
  require "bundler/gem_tasks"
3
3
  require "fileutils"
4
- require './lib/dur'
4
+ require './lib/cakery'
5
5
 
6
6
  #Gem things
7
7
  #############################################################################
8
8
  #Upgrade version of gem
9
9
  def upgrade_version
10
- versionf = './lib/dur/version.rb'
10
+ versionf = './lib/cakery/version.rb'
11
11
  require versionf
12
12
 
13
13
  #Upgrade version '0.0.1' => '0.0.2'
14
- version = dur::VERSION
14
+ version = Cakery::VERSION
15
15
  new_version = version.split(".")
16
16
  new_version[2] = new_version[2].to_i + 1
17
17
  new_version = new_version.join(".")
@@ -30,9 +30,9 @@ task :push do
30
30
  `git push`
31
31
  `git tag #{version}`
32
32
  `git push origin #{version}`
33
- `gem build dur.gemspec`
34
- `gem push dur-#{version}.gem`
35
- `rm dur-#{version}.gem`
33
+ `gem build cakery.gemspec`
34
+ `gem push cakery-#{version}.gem`
35
+ `rm cakery-#{version}.gem`
36
36
  end
37
37
 
38
38
  #############################################################################
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Cakery::VERSION
9
9
  spec.authors = ["seo"]
10
10
  spec.email = ["seotownsend@icloud.com"]
11
- spec.summary = "A boring javascript application framework"
12
- spec.description = "cakery is a cross-platform application framework system that exports javascript files"
11
+ spec.summary = "Combine many files into one intelligently"
12
+ spec.description = "Combine many files into one intelligently. Cakery has a simple *DSL* that allows you to glob directories and pass strings to an **erb** file. You can also add **macros** to a cakery pipeline. Think about it as a more generic version of [Sprockets](https://github.com/sstephenson/sprockets)."
13
13
  spec.homepage = "https://github.com/sotownsend/cakery"
14
14
  spec.license = "MIT"
15
15
 
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake", "~> 10.3"
23
23
  spec.add_development_dependency "rspec", "~> 3.2"
24
+ spec.add_development_dependency "pry", "~> 0.10"
24
25
  end
@@ -1,3 +1,90 @@
1
+ require 'cakery/macro'
2
+ require 'erb'
3
+
1
4
  module Cakery
5
+ class Cakery
6
+ attr_accessor :src
7
+
8
+ #Create a new cakery (recipe) with an erb file
9
+ def initialize erb_path, &block
10
+ raise "You gave cakery the file: #{erb_path.inspect} but this wasn't a file" unless File.file?(erb_path)
11
+
12
+ #Create a new erb compiler
13
+ @erb_src = File.read(erb_path)
14
+ @erbc = ERB.new(@erb_src)
15
+
16
+ @block = block
17
+ end
18
+
19
+ def bake
20
+ ctx = CakeryERBContext.new
21
+ @block.call(ctx)
22
+ @src = @erbc.result(ctx.get_binding)
23
+ end
24
+ end
25
+
26
+ class CakeryERBContext
27
+ def initialize
28
+ end
29
+
30
+ def method_missing name, *args, &block
31
+ if name =~ /=/
32
+ name = ('@'+name.to_s.gsub(/=/, "")).to_sym
33
+ self.instance_variable_set(name, args.first)
34
+ else
35
+ return CakeERBContextTwoClauseHelper.new(self, name)
36
+ end
37
+ end
38
+
39
+ def get_binding
40
+ return binding
41
+ end
42
+ end
43
+
44
+ #Allow things like r.my_secret << './secret, this handles the '<<' part and
45
+ #is given 'my_secret' as a name
46
+ class CakeERBContextTwoClauseHelper
47
+ def initialize erb_context, name
48
+ @erb_context = erb_context
49
+ @name = name
50
+ @macros = []
51
+ end
52
+
53
+ def <<(e)
54
+ vname = ('@'+@name.to_s.gsub(/=/, "")).to_sym
55
+ out = ""
56
+
57
+ #Append all files or it's a macro class
58
+ if e.class == String
59
+ fpaths = Dir[e].select{|e| File.file?(e)}
60
+ fpaths.each do |fpath|
61
+ out << File.read(fpath)
62
+ end
63
+
64
+ #Run through each macro and run it in the reverse
65
+ #order that we put it in so that
66
+ #r.var << MyMacroA << MyMacroB << "./directory" will execute first MyMacroB and then MyMacroA
67
+ while macro = @macros.pop
68
+ out = macro.new.process(out)
69
+ end
70
+
71
+ @erb_context.instance_variable_set(vname, "") unless @erb_context.instance_variable_defined?(vname)
72
+ v = @erb_context.instance_variable_get(vname)
73
+ v += out
74
+ @erb_context.instance_variable_set(vname, v)
75
+
76
+ else
77
+ #Assume it's a macro, save it onto the stack
78
+ @macros << e
79
+
80
+ #Return self, recurse because there should be a string (or another macro)
81
+ #to the right of this one
82
+ return self
83
+ end
84
+ end
85
+ end
2
86
 
87
+ def self.new *params, &block
88
+ return Cakery.new(*params, &block)
89
+ end
3
90
  end
@@ -0,0 +1,5 @@
1
+ module Cakery
2
+ class Macro
3
+
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Cakery
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/logo.png CHANGED
Binary file
@@ -0,0 +1 @@
1
+ hello world
@@ -0,0 +1,2 @@
1
+ hello world 1
2
+ goodbye world 2
@@ -0,0 +1 @@
1
+ hello world
@@ -0,0 +1 @@
1
+ goodbye world
@@ -0,0 +1 @@
1
+ test
@@ -0,0 +1 @@
1
+ <%= @secret %>
@@ -0,0 +1 @@
1
+ <%= @secret %>
@@ -0,0 +1 @@
1
+ <%= @secret %>
@@ -0,0 +1 @@
1
+ <%= @secret %>
@@ -0,0 +1 @@
1
+ <%= @secret %>
@@ -0,0 +1,155 @@
1
+ require 'securerandom'
2
+ require 'cakery'
3
+
4
+ RSpec.describe "Baking" do
5
+ def cakery_path name
6
+ return File.join(File.dirname(__FILE__), "assets/#{name}.cakery")
7
+ end
8
+
9
+ #go into ./spec/assets/proj/$project_name and use
10
+ #it as a project folder
11
+ def cd_proj name
12
+ Dir.chdir File.join(File.dirname(__FILE__), "assets/proj/#{name}") do
13
+ yield
14
+ end
15
+ end
16
+
17
+ it "can run a no variable cakery file" do
18
+ cp = cakery_path "test0"
19
+ c = Cakery.new(cp) do |r|
20
+ end
21
+
22
+ c.bake
23
+ expect(c.src).to eq("test\n")
24
+ end
25
+
26
+ it "can use a text variable in the cakery file" do
27
+ cp = cakery_path "test1"
28
+ secret = SecureRandom.hex
29
+
30
+ c = Cakery.new(cp) do |r|
31
+ r.secret = secret
32
+ end
33
+
34
+ c.bake
35
+ expect(c.src).to eq("#{secret}\n")
36
+ end
37
+
38
+
39
+ it "can use a directory append" do
40
+ cp = cakery_path "test2"
41
+
42
+ c = Cakery.new(cp) do |r|
43
+ r.secret << './secret/*'
44
+ end
45
+
46
+ cd_proj "test2" do
47
+ c.bake
48
+ end
49
+ expect(c.src).to eq("hello world\n\n")
50
+ end
51
+
52
+ it "can use a directory append many" do
53
+ cp = cakery_path "test3"
54
+
55
+ c = Cakery.new(cp) do |r|
56
+ r.secret << './secret/**/*'
57
+ end
58
+
59
+ cd_proj "test3" do
60
+ c.bake
61
+ end
62
+ expect(c.src).to eq("hello world\n\n")
63
+ end
64
+
65
+ it "will not get depth if not requested" do
66
+ cp = cakery_path "test3"
67
+
68
+ c = Cakery.new(cp) do |r|
69
+ r.secret << './secret/*'
70
+ end
71
+
72
+ cd_proj "test3" do
73
+ c.bake
74
+ end
75
+ expect(c.src).to eq("\n")
76
+ end
77
+
78
+ it "supports macros" do
79
+ cp = cakery_path "test4"
80
+
81
+ class MyMacro < Cakery::Macro
82
+ def process str
83
+ out = ""
84
+ str.split("\n").each do |line|
85
+ if line =~ /hello/
86
+ out += line.gsub(/hello/, "goodbye")
87
+ else
88
+ out += line
89
+ end
90
+
91
+ out += "\n"
92
+ end
93
+ out
94
+ end
95
+ end
96
+
97
+ c = Cakery.new(cp) do |r|
98
+ r.secret << MyMacro << './secret/*'
99
+ end
100
+
101
+ cd_proj "test4" do
102
+ c.bake
103
+ end
104
+
105
+ #Started out with hello world 1, goodbye world 2 -> goodbye world 1, goodbye world 2
106
+ expect(c.src).to eq("goodbye world 1\ngoodbye world 2\n\n")
107
+ end
108
+
109
+ #it "supports stacked macros" do
110
+ #cp = cakery_path "test4"
111
+
112
+ #class MyMacro < Cakery::Macro
113
+ #def process str
114
+ #out = ""
115
+ #str.split("\n").each do |line|
116
+ #if line =~ /hello/
117
+ #out += line.gsub(/hello/, "goodbye")
118
+ #elsif line =~ /goodbye/
119
+ #out += line.gsub(/goodbye/, "fuck_you")
120
+ #else
121
+ #out += line
122
+ #end
123
+
124
+ #out += "\n"
125
+ #end
126
+ #out
127
+ #end
128
+ #end
129
+
130
+ #c = Cakery.new(cp) do |r|
131
+ #r.secret << MyMacro << MyMacro << './secret/*'
132
+ #end
133
+
134
+ #cd_proj "test4" do
135
+ #c.bake
136
+ #end
137
+
138
+ ##Started out with hello world 1, goodbye world 2 -> goodbye world 1, goodbye world 2
139
+ #expect(c.src).to eq("fuck_you world 1\nfuck_you world 2\n\n")
140
+ #end
141
+
142
+ #it "supports two dir sources to one variable" do
143
+ #cp = cakery_path "test5"
144
+
145
+ #c = Cakery.new(cp) do |r|
146
+ #r.secret << "./secret1/*"
147
+ #r.secret << "./secret2/*"
148
+ #end
149
+
150
+ #cd_proj "test5" do
151
+ #c.bake
152
+ #end
153
+ #expect(c.src).to eq("hello world\ngoodbye world\n\n")
154
+ #end
155
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cakery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-21 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,8 +52,24 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.2'
55
- description: cakery is a cross-platform application framework system that exports
56
- javascript files
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ description: Combine many files into one intelligently. Cakery has a simple *DSL*
70
+ that allows you to glob directories and pass strings to an **erb** file. You can
71
+ also add **macros** to a cakery pipeline. Think about it as a more generic version
72
+ of [Sprockets](https://github.com/sstephenson/sprockets).
57
73
  email:
58
74
  - seotownsend@icloud.com
59
75
  executables: []
@@ -68,9 +84,21 @@ files:
68
84
  - Rakefile
69
85
  - cakery.gemspec
70
86
  - lib/cakery.rb
87
+ - lib/cakery/macro.rb
71
88
  - lib/cakery/version.rb
72
89
  - logo.png
73
- - spec/test_spec.rb
90
+ - spec/assets/proj/test2/secret/secret.txt
91
+ - spec/assets/proj/test3/secret/deeper/secret.txt
92
+ - spec/assets/proj/test4/secret/secret.txt
93
+ - spec/assets/proj/test5/secret1/secret.txt
94
+ - spec/assets/proj/test5/secret2/secret.txt
95
+ - spec/assets/test0.cakery
96
+ - spec/assets/test1.cakery
97
+ - spec/assets/test2.cakery
98
+ - spec/assets/test3.cakery
99
+ - spec/assets/test4.cakery
100
+ - spec/assets/test5.cakery
101
+ - spec/bake_spec.rb
74
102
  homepage: https://github.com/sotownsend/cakery
75
103
  licenses:
76
104
  - MIT
@@ -94,6 +122,17 @@ rubyforge_project:
94
122
  rubygems_version: 2.4.6
95
123
  signing_key:
96
124
  specification_version: 4
97
- summary: A boring javascript application framework
125
+ summary: Combine many files into one intelligently
98
126
  test_files:
99
- - spec/test_spec.rb
127
+ - spec/assets/proj/test2/secret/secret.txt
128
+ - spec/assets/proj/test3/secret/deeper/secret.txt
129
+ - spec/assets/proj/test4/secret/secret.txt
130
+ - spec/assets/proj/test5/secret1/secret.txt
131
+ - spec/assets/proj/test5/secret2/secret.txt
132
+ - spec/assets/test0.cakery
133
+ - spec/assets/test1.cakery
134
+ - spec/assets/test2.cakery
135
+ - spec/assets/test3.cakery
136
+ - spec/assets/test4.cakery
137
+ - spec/assets/test5.cakery
138
+ - spec/bake_spec.rb
@@ -1,5 +0,0 @@
1
- RSpec.describe "Hello" do
2
- it "Works" do
3
- puts "Hello"
4
- end
5
- end