wavy 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5959e7b31a7565a63bdec8802465c0fb4389527
4
+ data.tar.gz: 3011bef5bf3f58bd30903199ef885c0e04de76b5
5
+ SHA512:
6
+ metadata.gz: dfba4d12c8b77b39955fe16d488644962767985d8dafb861123158365dbec2984ccca18dda71d6cbbb137a6d3783494633093fc977e8263293d2249384f9c41c
7
+ data.tar.gz: 81241688917074d656d9608e9f6697efd5e652866dad8221d86c1ca68a5043c4a77a661ce5dfc64449481a3d7d409c36c735ffaaa27c73401d179f5139ca4a23
data/bin/wavy ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wavy'
4
+
5
+ Wavy.execute(ARGV)
data/lib/wavy/core.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'wavy/utils'
2
+ require 'wavy/nodes'
3
+ require 'wavy/models'
4
+ require 'wavy/parsers'
5
+
6
+ module Wavy
7
+
8
+ # File suffix
9
+ FILE_SUFFIX = ".wavy"
10
+
11
+ # Find and read files
12
+ FILE_IMPORTER = Wavy::Utils::FileSys
13
+
14
+ class Core
15
+
16
+ String @root_path
17
+
18
+ String @view
19
+ String @config
20
+ String @filename
21
+
22
+ # Creates a new Core
23
+ #
24
+ # @param (String) config Main configuration file
25
+ # @param (String) view Template to compile
26
+ # @param (Boolean|String) Path to save output
27
+ def initialize(config, view, save)
28
+ @view = view
29
+ @config = config
30
+ @save = save
31
+ @config_root = File.expand_path(File.dirname(@config))
32
+ @filename = File.basename(@view)
33
+ end
34
+
35
+ # Reads configuration and view files. Begins parsing.
36
+ def compile()
37
+ begin
38
+ @config = FILE_IMPORTER.load(@config, true)
39
+ Wavy::Parsers::Import.load(@config, @config_root)
40
+ Wavy::Parsers::Import.extract
41
+
42
+ @view = FILE_IMPORTER.load(@view)
43
+ render(@view)
44
+ rescue Exception => e
45
+ puts e.message
46
+ end
47
+ end
48
+
49
+ # Saves parsed template.
50
+ #
51
+ # @param (String) view Content of the view
52
+ def render(view)
53
+ output = Wavy::Models::Template.new(view).parse
54
+
55
+ if @save != false
56
+ filename = @filename.gsub("#{FILE_SUFFIX}", "")
57
+ path = File.expand_path(@save)
58
+ path = path + "/" + filename
59
+
60
+ begin
61
+ file = File.open(path, "w")
62
+ file.write(output)
63
+ rescue IOError => e
64
+ raise 'Could not save file.'
65
+ ensure
66
+ file.close unless file == nil
67
+ end
68
+ else
69
+ puts output
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ end
data/lib/wavy/help.rb ADDED
@@ -0,0 +1,8 @@
1
+ WAVY_HELP_OUTPUT = "Usage: wavy [options] [CONFIG] [INPUT] [OUTPUT]
2
+
3
+ Description:
4
+ Converts Wavy files to HTML
5
+
6
+ Options:
7
+ -v, --version Prints Version
8
+ "
@@ -0,0 +1,37 @@
1
+ module Wavy
2
+
3
+ module Models
4
+
5
+ class Imports
6
+
7
+ @data = {}
8
+
9
+ # Add an import to the data model.
10
+ #
11
+ # @param (String) id Unique name of the import
12
+ # @param (Tree::ImportNode) node Import node object
13
+ # @param (String) file File path
14
+ def self.add(id, node, file = '')
15
+ if file == ''
16
+ file = id
17
+ end
18
+
19
+ if !@data[id]
20
+ @data[id] = node
21
+ else
22
+ puts file + ' is being imported more than once.'
23
+ end
24
+ end
25
+
26
+ # Get all of the import definitions.
27
+ #
28
+ # @return (Object) @data Object of imports
29
+ def self.get()
30
+ return @data
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,30 @@
1
+ module Wavy
2
+
3
+ module Models
4
+
5
+ class Mixins
6
+
7
+ @data = {}
8
+
9
+ # Add a mixin to the data model.
10
+ #
11
+ # @param (String) id Unique name of the import
12
+ # @param (Tree::MixinNode) node Mixin node object
13
+ def self.add(id, node)
14
+ if !@data[id]
15
+ @data[id] = node
16
+ end
17
+ end
18
+
19
+ # Get all of the mixin definitions.
20
+ #
21
+ # @return (Object) @data Object of mixins
22
+ def self.get()
23
+ return @data
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,34 @@
1
+ module Wavy
2
+
3
+ module Models
4
+
5
+ class Template
6
+
7
+ # (String) Original template content
8
+ attr_reader :content
9
+
10
+ # (String) Compiled template content
11
+ attr_reader :compiled
12
+
13
+ # Creates a new view template
14
+ #
15
+ # @return (String) content The view content (string/html)
16
+ def initialize(content)
17
+ @content = content
18
+ @compiled = ""
19
+ end
20
+
21
+ # Parse the template.
22
+ #
23
+ # @return (String) @compiled Compiled output
24
+ def parse
25
+ @compiled = Wavy::Parsers::Mixin.parse(@content)
26
+
27
+ return @compiled
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,8 @@
1
+ module Wavy
2
+ module Models
3
+ end
4
+ end
5
+
6
+ require 'wavy/models/imports'
7
+ require 'wavy/models/mixins'
8
+ require 'wavy/models/template'
@@ -0,0 +1,23 @@
1
+ module Wavy
2
+
3
+ module Nodes
4
+
5
+ class Import
6
+
7
+ # (String) Content of import file
8
+ attr_reader :content
9
+
10
+ # Creates a new Import node
11
+ #
12
+ # @param (String) path Path to file
13
+ # @param (String) content Content of file
14
+ def initialize(path, content)
15
+ @path = path
16
+ @content = content
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,47 @@
1
+ module Wavy
2
+
3
+ module Nodes
4
+
5
+ class Mixin
6
+
7
+ # (Array) Params of mixin
8
+ attr_reader :params
9
+
10
+ # (String) Content within mixin
11
+ attr_reader :content
12
+
13
+ # Creates a new Mixin node
14
+ #
15
+ # @param (String) name Name of mixin
16
+ # @param (String) params Specified arguments
17
+ # @param (String) content Content of mixin
18
+ def initialize(name, params, content)
19
+ @name = name
20
+ @params = get_params(params)
21
+ @content = content
22
+ end
23
+
24
+ # Converts string of mixin parameters to an array.
25
+ #
26
+ # @return (Array) params Array of clean parameters
27
+ def get_params(args)
28
+ params = []
29
+
30
+ args = args.split(",")
31
+
32
+ args.each do |arg|
33
+ arg = arg.strip
34
+ if arg.index('$') == 0
35
+ arg[0] = ''
36
+ params.push(arg)
37
+ end
38
+ end
39
+
40
+ return params
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
data/lib/wavy/nodes.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Wavy
2
+ module Nodes
3
+ end
4
+ end
5
+
6
+ require 'wavy/nodes/import'
7
+ require 'wavy/nodes/mixin'
@@ -0,0 +1,45 @@
1
+ module Wavy
2
+
3
+ module Parsers
4
+
5
+ class Import
6
+
7
+ # Creates a new Core
8
+ #
9
+ # @param (String) content Content of the file
10
+ # @param (String) root Root path of the file
11
+ def self.load(content, root)
12
+ pattern = /^(@import)\s\"(.*)\"/
13
+ matches = content.scan(pattern)
14
+
15
+ if matches.length > 0
16
+ matches.each do |match|
17
+ file_path = match[1]
18
+ path = root + "/" + file_path + FILE_SUFFIX
19
+
20
+ file_content = FILE_IMPORTER.load(path)
21
+ import_node = Wavy::Nodes::Import.new(path, file_content)
22
+
23
+ current_root = File.expand_path(File.dirname(path))
24
+
25
+ self.load(file_content, current_root)
26
+
27
+ Wavy::Models::Imports.add(path, import_node)
28
+ end
29
+ end
30
+ end
31
+
32
+ # Extracts all user defintions
33
+ def self.extract()
34
+ files = Wavy::Models::Imports.get
35
+
36
+ files.each do |key, value|
37
+ Wavy::Parsers::Mixin.defined(value.content)
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,71 @@
1
+ module Wavy
2
+
3
+ module Parsers
4
+
5
+ class Mixin
6
+
7
+ # Finds all user-defined mixins.
8
+ #
9
+ # @param (String) data Content
10
+ def self.defined(data)
11
+ pattern = /^(@mixin)\s(.*)\((.*)\.*\)\s{((?:[^{}]|{\$([^}]*)}|{{([^}]*)}})*)}/
12
+ matches = data.scan(pattern)
13
+
14
+ if matches.length > 0
15
+ matches.each do |match|
16
+ mixin_node = Wavy::Nodes::Mixin.new(match[1], match[2], match[3])
17
+
18
+ Wavy::Models::Mixins.add(match[1], mixin_node)
19
+ end
20
+ end
21
+ end
22
+
23
+ # Finds all included mixins.
24
+ #
25
+ # @param (String) data Content
26
+ #
27
+ # @return (String) data Parsed content
28
+ def self.parse(template)
29
+ # Search for mixin includes
30
+ pattern = /(@include)\s(.*)\((.*)\)/
31
+ matches = template.scan(pattern)
32
+
33
+ mixins = Wavy::Models::Mixins.get
34
+
35
+ # Go through and parse each include
36
+ if matches.length > 0
37
+ matches.each do |match|
38
+ if(mixins[match[1]])
39
+ mixin = mixins[match[1]]
40
+ params = match[2].split(",");
41
+ content = mixin.content
42
+
43
+ # Replace variables
44
+ mixin.params.each_with_index do |param, index|
45
+ if params[index]
46
+ new_param = params[index].strip.gsub(/\'/, "")
47
+ else
48
+ new_param = ""
49
+ end
50
+
51
+ content = content.gsub("{$#{param}}", new_param)
52
+ end
53
+
54
+ # Search for includes within mixins
55
+ content = parse(content)
56
+
57
+ # Find mixin string to replace
58
+ find = "@include #{match[1]}(#{match[2]})"
59
+ template = template.gsub(find, content)
60
+ end
61
+ end
62
+ end
63
+
64
+ return template
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,12 @@
1
+ module Wavy
2
+
3
+ # The character to parse a HTML element
4
+ CHAR_DEFINE_HTML = "~"
5
+
6
+ module Parsers
7
+ end
8
+
9
+ end
10
+
11
+ require 'wavy/parsers/import'
12
+ require 'wavy/parsers/mixin'
@@ -0,0 +1,41 @@
1
+ module Wavy
2
+
3
+ module Utils
4
+
5
+ class FileSys
6
+
7
+ # Check and load file
8
+ #
9
+ # @param (String) name File path
10
+ # @param (Boolean) partial_check Also check for "_" on file
11
+ def self.load(name, partial_check = true)
12
+ if File.exists?(name)
13
+ open(name).read
14
+ else
15
+ if partial_check
16
+ load_partial(name)
17
+ else
18
+ raise 'File not found.'
19
+ end
20
+ end
21
+ end
22
+
23
+ # Check if a file with "_" exists
24
+ #
25
+ # @param (String) name File path
26
+ def self.load_partial(name)
27
+ a = name.split("/")
28
+ new_name = "_" + a[-1]
29
+ a = a.first a.size - 1
30
+
31
+ if a.length > 1
32
+ new_name = a.join("/") + "/" + new_name
33
+ end
34
+
35
+ load(new_name, false)
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
data/lib/wavy/utils.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Wavy
2
+ module Utils
3
+ end
4
+ end
5
+
6
+ require 'wavy/utils/filesys'
@@ -0,0 +1,13 @@
1
+ module Wavy
2
+
3
+ VERSION = '0.0.1'
4
+
5
+ class Version
6
+
7
+ def self.get
8
+ return "Wavy #{VERSION}"
9
+ end
10
+
11
+ end
12
+
13
+ end
data/lib/wavy.rb ADDED
@@ -0,0 +1,58 @@
1
+ require 'wavy/version'
2
+ require 'wavy/help'
3
+
4
+ module Wavy
5
+
6
+ class << self
7
+
8
+ end
9
+
10
+ # Compile specified view(s)
11
+ #
12
+ # @param (String) config Main configuration file
13
+ # @param (String) view Template to compile
14
+ # @param (Boolean|String) Path to save output
15
+ def self.compile(config, view, save = false)
16
+ core = Core.new(config, view, save).compile
17
+ end
18
+
19
+ # Execute compile method via bash
20
+ #
21
+ # @param (ARGV) args Arguments
22
+ def self.execute(args)
23
+ begin
24
+ if args[0]
25
+ case args[0]
26
+ when "--help", "-h"
27
+ puts "#{WAVY_HELP_OUTPUT}"
28
+ when "--version", "-v"
29
+ puts Wavy::Version.get
30
+ else
31
+ config = args[0]
32
+
33
+ if args[1]
34
+ view = args[1]
35
+ else
36
+ raise 'Missing template.'
37
+ end
38
+
39
+ if !args[2]
40
+ save = false
41
+ else
42
+ save = args[2]
43
+ end
44
+
45
+ compile(config, view, save)
46
+ end
47
+ else
48
+ raise 'Missing main configuration file.'
49
+ end
50
+ rescue Exception => e
51
+ puts e.message
52
+ abort
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ require 'wavy/core'
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wavy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Govaere
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Wavy is a simple templating engine for HTML.
14
+ email: matthew.govaere@gmail.com
15
+ executables:
16
+ - wavy
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/wavy
21
+ - lib/wavy.rb
22
+ - lib/wavy/core.rb
23
+ - lib/wavy/help.rb
24
+ - lib/wavy/models.rb
25
+ - lib/wavy/models/imports.rb
26
+ - lib/wavy/models/mixins.rb
27
+ - lib/wavy/models/template.rb
28
+ - lib/wavy/nodes.rb
29
+ - lib/wavy/nodes/import.rb
30
+ - lib/wavy/nodes/mixin.rb
31
+ - lib/wavy/parsers.rb
32
+ - lib/wavy/parsers/import.rb
33
+ - lib/wavy/parsers/mixin.rb
34
+ - lib/wavy/utils.rb
35
+ - lib/wavy/utils/filesys.rb
36
+ - lib/wavy/version.rb
37
+ homepage: http://wavy.it
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.4.1
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: A simple templating engine for HTML.
61
+ test_files: []