rego_wcm 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ Gemfile.lock
3
+ pkg/*
4
+ vendor/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rego.gemspec
4
+ gemspec
@@ -0,0 +1,3 @@
1
+ # REGO - A CMS generating static HTML by building blocks.
2
+
3
+ NO DOCUMENTS YET.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8; -*-
3
+ #
4
+ # rego.rb: A web contents management system to generate static pages by building blocks.
5
+ #
6
+ # Copyright (C) 2010 by TADA Tadashi <t@tdtds.jp>
7
+ # Distributed under GPL.
8
+ #
9
+
10
+ class UsageError < ArgumentError; end
11
+
12
+ begin
13
+ opts = {
14
+ :server => 'production',
15
+ }
16
+ while opt = ARGV.shift
17
+ case opt
18
+ when '-f', '--force' # force options
19
+ opts[:force] = true
20
+ when '-V', '--verbose' # verbose options
21
+ opts[:verbose] = true
22
+ when '-L', '--lib' # append lib path
23
+ new_lib = ARGV.shift
24
+ raise ArgumentError::new( "need a parameter for #{opt} option." ) unless new_lib
25
+ $:.unshift( new_lib )
26
+ when '-s', '--server'
27
+ server = ARGV.shift
28
+ raise ArgumentError::new( "need a parameter for #{opt} option." ) unless server
29
+ opts[:server] = server
30
+ when /^-/
31
+ raise ArgumentError::new( "invalid option: #{opt}." )
32
+ else
33
+ ARGV.unshift opt
34
+ break
35
+ end
36
+ end
37
+
38
+ src = ARGV.shift
39
+ dest = ARGV.shift
40
+ raise UsageError::new( 'no src or dest path.' ) unless src and dest
41
+
42
+ require 'rego'
43
+ REGO::App::new( src, dest, opts ).run
44
+ exit 0
45
+
46
+ rescue UsageError
47
+ require 'rego/version'
48
+
49
+ $stderr.puts <<-USAGE.gsub( /^\t\t/, '' )
50
+ #{File::basename $0}: A WCM system to generate static pages by building blocks. Ver.#{REGO::VERSION}
51
+ usage: #{File::basename $0} [-f] [-V] [-L <path>] [-s <env>] <src_dir> <dest_dir>
52
+
53
+ --force, -f: force generating contents.
54
+ --verbose, -V: show verbose messages.
55
+ --lib, -L <path>: append block library path of your web site.
56
+ --server, -s <env>: publishing environment name. default "production".
57
+ src_dir: source directory of contents.
58
+ dest_dir: destination dirctory to generate contents.
59
+ USAGE
60
+ exit 1
61
+
62
+ rescue ArgumentError
63
+ $stderr.puts $!
64
+ exit 1
65
+ end
@@ -0,0 +1,8 @@
1
+ #
2
+ # rego.rb: A web contents management system to generate static pages by building blocks.
3
+ #
4
+ # Copyright (C) 2010 by TADA Tadashi
5
+ # Distributed under GPL.
6
+ #
7
+ require 'rego/app'
8
+ require 'rego/block/template'
@@ -0,0 +1,92 @@
1
+ #
2
+ # app.rb: REGO Application
3
+ #
4
+ # Copyright (C) 2010 by TADA Tadashi
5
+ # Distributed under GPL.
6
+ #
7
+ require 'pathname'
8
+
9
+ module REGO
10
+ class REGOError < ::StandardError; end
11
+ class MakeLink < REGOError; end
12
+
13
+ class App
14
+ def initialize( src, dest, opt = {} )
15
+ @src, @dest, @opt = src, dest, opt
16
+ @src.chop! if %r|/$| =~ @src
17
+ @dest.chop! if %r|/$| =~ @dest
18
+ @env = {
19
+ :src => @src,
20
+ :dest => @dest
21
+ }.update( @opt )
22
+ end
23
+
24
+ def run
25
+ Pathname::glob( "#{@src}/**/{.*,*}" ) do |src|
26
+ relative = src.to_s[@src.size, src.to_s.size]
27
+ @env[:src_file] = relative
28
+ @env[:dest_file] = relative.dup
29
+
30
+ if src.directory?
31
+ Pathname::new( @dest + relative ).mkpath
32
+ else
33
+ case src.to_s
34
+ when /\.rego$/
35
+ @env[:dest_file] = relative.sub( /\.rego$/, '' )
36
+ begin
37
+ next if !@opt[:force] && (src.mtime < Pathname::new( dest_file( @env ) ).mtime)
38
+ rescue Errno::ENOENT
39
+ end
40
+ $stderr.puts relative if @opt[:verbose]
41
+ processing( @env, :template )
42
+ when /\.ignore$/
43
+ # ignore this file
44
+ else
45
+ processing( @env, :symlink )
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ private
52
+ def src_file( env )
53
+ env[:src] + env[:src_file]
54
+ end
55
+
56
+ def dest_file( env )
57
+ env[:dest] + env[:dest_file]
58
+ end
59
+
60
+ def processing( env, filter )
61
+ result = ''
62
+ begin
63
+ File::open( src_file( env ), 'r:utf-8' ) do |f|
64
+ result = __send__( filter, f.read, env )
65
+ end
66
+ File::open( dest_file( env ), 'w' ) do |f|
67
+ f.write( result )
68
+ end
69
+ rescue MakeLink
70
+ Pathname::new( dest_file( env ) ).make_symlink( src_file( env ) ) rescue Errno::EEXIST
71
+ end
72
+ end
73
+
74
+ def template( tmpl, env )
75
+ tmpl.insert( 0, "do_template( env ) {\n" ) << "\n}"
76
+ instance_eval( tmpl )
77
+ end
78
+
79
+ def do_template( env, &block )
80
+ REGO::Block::Template::new( env, &block ).result
81
+ end
82
+
83
+ def dead_copy( tmpl, env )
84
+ tmpl
85
+ end
86
+
87
+ def symlink( tmpl, env )
88
+ raise MakeLink::new
89
+ end
90
+ end
91
+ end
92
+
@@ -0,0 +1,37 @@
1
+ #
2
+ # html.rb: REGO HTML and elements Block
3
+ #
4
+ # Copyright (C) 2010 by TADA Tadashi
5
+ # Distributed under GPL.
6
+ #
7
+
8
+ module REGO::Block
9
+ class Html < Template
10
+ def result
11
+ <<-HTML.gsub( /^\t*/, '' )
12
+ <html>
13
+ #{super}
14
+ </html>
15
+ HTML
16
+ end
17
+ end
18
+
19
+ class Head < Template
20
+ def result
21
+ raise ::StandardError::new( 'no title in head' ) unless @title
22
+ <<-HTML
23
+ <title>#{@title}</title>
24
+ HTML
25
+ end
26
+ end
27
+
28
+ class Body < Template
29
+ def result
30
+ <<-HTML
31
+ <body>
32
+ <h1>#{@h1}</h1>
33
+ </body>
34
+ HTML
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ # template.rb: REGO Template as a default Block
3
+ #
4
+ # Copyright (C) 2010 by TADA Tadashi
5
+ # Distributed under GPL.
6
+ #
7
+
8
+ module REGO::Block
9
+ class Template
10
+ def initialize( env, &block )
11
+ @env = env
12
+ @child = []
13
+ instance_eval( &block ) if block_given?
14
+ self
15
+ end
16
+
17
+ def result
18
+ @child.join( "\n" )
19
+ end
20
+
21
+ def method_missing( name, *args, &block )
22
+ if block
23
+ begin
24
+ klass = REGO::Block::const_get( name.to_s.capitalize )
25
+ @child << klass::new( @env, &block ).result
26
+ rescue NameError
27
+ begin
28
+ require name.to_s
29
+ rescue LoadError
30
+ require "rego/block/#{name}"
31
+ end
32
+ retry
33
+ end
34
+ else
35
+ instance_variable_set "@#{name}", args[0]
36
+ end
37
+ self
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module REGO
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rego/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rego_wcm"
7
+ s.version = REGO::VERSION
8
+ s.authors = ["TADA Tadashi"]
9
+ s.email = ["t@tdtds.jp"]
10
+ s.homepage = ""
11
+ s.summary = %q{A CMS generating static HTML by building blocks.}
12
+ s.description = %q{}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # specify any dependencies here; for example:
20
+ # s.add_development_dependency "rspec"
21
+ # s.add_runtime_dependency "rest-client"
22
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rego_wcm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - TADA Tadashi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ''
15
+ email:
16
+ - t@tdtds.jp
17
+ executables:
18
+ - rego
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - README.md
25
+ - Rakefile
26
+ - bin/rego
27
+ - lib/rego.rb
28
+ - lib/rego/app.rb
29
+ - lib/rego/block/html.rb
30
+ - lib/rego/block/template.rb
31
+ - lib/rego/version.rb
32
+ - rego.gemspec
33
+ homepage: ''
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.11
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: A CMS generating static HTML by building blocks.
57
+ test_files: []