qor_dsl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ *.rbc
2
+ *.sassc
3
+ .sass-cache
4
+ capybara-*.html
5
+ .rspec
6
+ /.bundle
7
+ /vendor/bundle
8
+ /log/*
9
+ /tmp/*
10
+ /db/*.sqlite3
11
+ /public/system/*
12
+ /coverage/
13
+ /spec/tmp/*
14
+ **.orig
15
+ rerun.txt
16
+ pickle-email-*.html
@@ -0,0 +1,4 @@
1
+ qor_dsl
2
+ =======
3
+
4
+ Qor DSL
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake'
5
+ require 'rubygems/package_task'
6
+ require 'rake/testtask'
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = false
13
+ end
14
+
15
+ task :default => :test
@@ -0,0 +1,11 @@
1
+ require 'qor_dsl/class_method'
2
+ require 'qor_dsl/config'
3
+ require 'qor_dsl/node'
4
+
5
+ module Qor
6
+ module Dsl
7
+ def self.included(base)
8
+ base.extend ClassMethods
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ module Qor
2
+ module Dsl
3
+ module ClassMethods
4
+ def node_root
5
+ @node_root ||= Qor::Dsl::Node.new
6
+ end
7
+
8
+ def node(type, options={}, &blk)
9
+ node_root.node(type, options, &blk)
10
+ end
11
+
12
+ def root
13
+ @root || load
14
+ end
15
+
16
+ def load(path=nil, opts={})
17
+ @load_path = path || @load_path
18
+ @root = (opts[:force] ? nil : @root) || load_file(@load_path)
19
+ @root
20
+ end
21
+
22
+ def load_file(file)
23
+ return unless File.exist?(file.to_s)
24
+ content = File.read(file)
25
+ node_root.config.instance_eval(content)
26
+ node_root
27
+ end
28
+
29
+ def find(*arguments)
30
+ root.find(*arguments)
31
+ end
32
+
33
+ def first(*arguments)
34
+ root.first(*arguments)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,44 @@
1
+ module Qor
2
+ module Dsl
3
+ class Config
4
+ attr_accessor :__node, :__name, :__parent, :__children, :__options, :__block
5
+
6
+ def initialize type, node=nil
7
+ self.__name = type
8
+ self.__node = node
9
+ end
10
+
11
+ def node(type, options={}, &blk)
12
+ child = Qor::Dsl::Config.new(type)
13
+ child.instance_eval(&blk) if block_given?
14
+ __add_child(type, options, child)
15
+
16
+ self
17
+ end
18
+
19
+ def __children
20
+ @__children ||= {}
21
+ end
22
+
23
+ def __add_child(type, options, child)
24
+ child.__parent = self
25
+ child.__options = options
26
+ self.__children[type.to_sym] = child
27
+
28
+ method_defination = <<-DOC
29
+ def #{type}(name=nil, opts={}, &blk)
30
+ config = __children['#{type}'.to_sym]
31
+ node = Qor::Dsl::Node.new(name)
32
+ node.add_config(config)
33
+ node.options = opts
34
+ node.block = blk
35
+ node.config.instance_eval(&blk) if block_given? && (config.__children.size > 0)
36
+ __node.add_child(node)
37
+ end
38
+ DOC
39
+
40
+ self.instance_eval method_defination
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,54 @@
1
+ module Qor
2
+ module Dsl
3
+ class Node
4
+ attr_accessor :name, :config, :parent, :children, :options, :block
5
+
6
+ def initialize(name=nil, options={})
7
+ self.name = name
8
+ self.add_config(options[:config] || Qor::Dsl::Config.new('ROOT', self))
9
+ end
10
+
11
+ def add_config(config)
12
+ self.config = config
13
+ config.__node = self
14
+ end
15
+
16
+ def node(type, options={}, &blk)
17
+ config.node(type, options, &blk)
18
+ end
19
+
20
+ def children
21
+ @children ||= []
22
+ end
23
+
24
+ def config_options_for_child(type)
25
+ config.__children[type].__options || {}
26
+ end
27
+
28
+ def add_child(child)
29
+ child.parent = self
30
+ children << child
31
+ end
32
+
33
+ def find(type=nil, name=nil)
34
+ selected_children = children.select do |child|
35
+ (type.nil? ? true : (child.config.__name.to_s == type.to_s)) &&
36
+ (name.nil? ? true : (child.name.to_s == name.to_s))
37
+ end
38
+
39
+ return selected_children[0] if !name.nil? && selected_children.length == 1
40
+ return parent.find(type, name) if (selected_children.length == 0) && config_options_for_child(type)[:inherit]
41
+ selected_children
42
+ end
43
+
44
+ def first(type=nil, name=nil)
45
+ selected_children = find(type, name)
46
+ selected_children.is_a? Array ? selected_children[0] : selected_children
47
+ end
48
+
49
+ def value
50
+ options[:value] || (block.nil? ? name : block.call)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.authors = ["Jinzhu"]
4
+ gem.email = ["wosmvp@gmail.com"]
5
+ gem.description = %q{Qor DSL}
6
+ gem.summary = %q{Qor DSL}
7
+ gem.homepage = ""
8
+
9
+ gem.files = `git ls-files`.split($\)
10
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
+ gem.name = "qor_dsl"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = "0.0.1"
15
+ end
@@ -0,0 +1,32 @@
1
+ require 'qor_dsl'
2
+
3
+ module Layout
4
+ module Configuration
5
+ include Qor::Dsl
6
+
7
+ node :template
8
+
9
+ node :gadget do
10
+ node :desc
11
+
12
+ node :settings do
13
+ node :meta
14
+ end
15
+
16
+ node :context
17
+ node :template, :inherit => true
18
+ end
19
+
20
+ node :layout do
21
+ node :gadgets
22
+ end
23
+
24
+ node :action do
25
+ node :desc
26
+ node :detect
27
+ node :add_permission, {:allow_multi => true}
28
+
29
+ # alias_node :grand, :add_permission, {:name => "grand", :options => {}}, {:allow_multi => false}
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ template do
2
+ "Hello World"
3
+ end
4
+
5
+ gadget :product_link, :floating => true
6
+
7
+ gadget :quick_buy, :floating => true do
8
+ settings do
9
+ meta :product_code, :label => "Product code", :type => :string
10
+ meta :text, :label => "Text", :type => :string
11
+ meta :kind, :label => "Kind", :type => :select_one, :collection => ['light', 'dark']
12
+ meta :target, :label => "Target"
13
+ end
14
+
15
+ context do
16
+ {:kind => 'light'}.merge(meta_settings.symbolize_keys).merge(:express_link => "/products/#{meta_settings[:product_code]}/#{meta_settings[:color_code]}?express=true")
17
+ end
18
+
19
+ template do
20
+ <<-STRING
21
+ <a href="{{express_link}}" class="item product_express_box action other {{kind}} btn1"><span>{{text}}</span></a>
22
+ STRING
23
+ end
24
+ end
25
+
26
+ action :google do
27
+ desc "From Google"
28
+ detect do |app|
29
+ '...'
30
+ end
31
+ end
32
+
33
+ layout :home do
34
+ gadgets []
35
+ end
@@ -0,0 +1,20 @@
1
+ require 'minitest/autorun'
2
+ require File.join(File.dirname(__FILE__), 'configure')
3
+
4
+ describe Layout do
5
+ before do
6
+ Layout::Configuration.load('test/layout.rb')
7
+ @root = Layout::Configuration.root
8
+ end
9
+
10
+ it "has four children" do
11
+ # test query
12
+ Layout::Configuration.find(:gadget).length.must_equal 2
13
+ # test normal find
14
+ Layout::Configuration.find(:gadget, 'quick_buy').name.must_equal :quick_buy
15
+ # test Inherit
16
+ Layout::Configuration.find(:gadget, :product_link).find(:template)[0].value.must_equal "Hello World"
17
+
18
+ # More is coming... (test multi, alias_node)
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qor_dsl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jinzhu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Qor DSL
15
+ email:
16
+ - wosmvp@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - README.md
23
+ - Rakefile
24
+ - lib/qor_dsl.rb
25
+ - lib/qor_dsl/class_method.rb
26
+ - lib/qor_dsl/config.rb
27
+ - lib/qor_dsl/node.rb
28
+ - qor_dsl.gemspec
29
+ - test/configure.rb
30
+ - test/layout.rb
31
+ - test/layout_test.rb
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.24
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Qor DSL
56
+ test_files:
57
+ - test/configure.rb
58
+ - test/layout.rb
59
+ - test/layout_test.rb
60
+ has_rdoc: