hx 0.4.1 → 0.5.0
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.
- data/Rakefile +6 -2
- data/VERSION +1 -1
- data/lib/hx.rb +39 -0
- data/lib/hx/commandline.rb +14 -2
- data/lib/hx/listing/recursiveindex.rb +3 -3
- data/lib/hx/output/liquidtemplate.rb +8 -6
- metadata +8 -4
    
        data/Rakefile
    CHANGED
    
    | @@ -6,8 +6,12 @@ begin | |
| 6 6 | 
             
              Jeweler::Tasks.new do |gem|
         | 
| 7 7 | 
             
                gem.name = "hx"
         | 
| 8 8 | 
             
                gem.executables << 'hx'
         | 
| 9 | 
            -
                gem.summary = %Q{A miniature site generator.}
         | 
| 10 | 
            -
                gem.description =  | 
| 9 | 
            +
                gem.summary = %Q{A miniature static site generator.}
         | 
| 10 | 
            +
                gem.description = <<EOS
         | 
| 11 | 
            +
            Hx is a simple static site generator in the spirit of Hobix which reads a
         | 
| 12 | 
            +
            YAML configuration file, constructs a filter graph, and generates output
         | 
| 13 | 
            +
            files.
         | 
| 14 | 
            +
            EOS
         | 
| 11 15 | 
             
                gem.email = "mental@rydia.net"
         | 
| 12 16 | 
             
                gem.homepage = "http://github.com/mental/hx"
         | 
| 13 17 | 
             
                gem.authors = ["MenTaLguY"]
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.5.0
         | 
    
        data/lib/hx.rb
    CHANGED
    
    | @@ -478,7 +478,17 @@ class FileBuilder | |
| 478 478 | 
             
              end
         | 
| 479 479 |  | 
| 480 480 | 
             
              def build_file(path, entry)
         | 
| 481 | 
            +
                build_file_helper(path, entry, false)
         | 
| 482 | 
            +
              end
         | 
| 483 | 
            +
             | 
| 484 | 
            +
              def build_file_if_updated(path, entry)
         | 
| 485 | 
            +
                build_file_helper(path, entry, true)
         | 
| 486 | 
            +
              end
         | 
| 487 | 
            +
             | 
| 488 | 
            +
              def build_file_helper(path, entry, update_only)
         | 
| 481 489 | 
             
                filename = @output_dir + path
         | 
| 490 | 
            +
                return self if update_only and filename.exist? and \
         | 
| 491 | 
            +
                               entry['updated'] and filename.mtime >= entry['updated']
         | 
| 482 492 | 
             
                dirname = filename.parent
         | 
| 483 493 | 
             
                dirname.mkpath()
         | 
| 484 494 | 
             
                filename.open("wb") do |stream|
         | 
| @@ -486,6 +496,35 @@ class FileBuilder | |
| 486 496 | 
             
                end
         | 
| 487 497 | 
             
                self
         | 
| 488 498 | 
             
              end
         | 
| 499 | 
            +
              private :build_file_helper
         | 
| 500 | 
            +
            end
         | 
| 501 | 
            +
             | 
| 502 | 
            +
            class LazyContent
         | 
| 503 | 
            +
              def initialize(&block)
         | 
| 504 | 
            +
                raise ArgumentError, "No block given" unless block
         | 
| 505 | 
            +
                @content = nil
         | 
| 506 | 
            +
                @block = block
         | 
| 507 | 
            +
              end
         | 
| 508 | 
            +
             | 
| 509 | 
            +
              def to_s
         | 
| 510 | 
            +
                if @block
         | 
| 511 | 
            +
                  @content = @block.call
         | 
| 512 | 
            +
                  @block = nil
         | 
| 513 | 
            +
                end
         | 
| 514 | 
            +
                @content
         | 
| 515 | 
            +
              end
         | 
| 516 | 
            +
             | 
| 517 | 
            +
              def to_yaml(*args)
         | 
| 518 | 
            +
                to_s.to_yaml(*args)
         | 
| 519 | 
            +
              end
         | 
| 520 | 
            +
             | 
| 521 | 
            +
              def to_json(*args)
         | 
| 522 | 
            +
                to_s.to_json(*args)
         | 
| 523 | 
            +
              end
         | 
| 524 | 
            +
             | 
| 525 | 
            +
              def to_liquid(*args)
         | 
| 526 | 
            +
                to_s.to_liquid(*args)
         | 
| 527 | 
            +
              end
         | 
| 489 528 | 
             
            end
         | 
| 490 529 |  | 
| 491 530 | 
             
            end
         | 
    
        data/lib/hx/commandline.rb
    CHANGED
    
    | @@ -79,7 +79,7 @@ def self.main(*args) | |
| 79 79 | 
             
                site = Hx::Site.load(stream, options.config_file)
         | 
| 80 80 | 
             
              end
         | 
| 81 81 |  | 
| 82 | 
            -
              subcommand = args.shift || " | 
| 82 | 
            +
              subcommand = args.shift || "upgen"
         | 
| 83 83 | 
             
              method_name = "cmd_#{subcommand}".intern
         | 
| 84 84 | 
             
              begin
         | 
| 85 85 | 
             
                m = method(method_name)
         | 
| @@ -90,11 +90,23 @@ def self.main(*args) | |
| 90 90 | 
             
            end
         | 
| 91 91 |  | 
| 92 92 | 
             
            def self.cmd_regen(site)
         | 
| 93 | 
            +
              do_gen(site, false)
         | 
| 94 | 
            +
            end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
            def self.cmd_upgen(site)
         | 
| 97 | 
            +
              do_gen(site, true)
         | 
| 98 | 
            +
            end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
            def self.do_gen(site, update_only)
         | 
| 93 101 | 
             
              output_dir = Hx.get_pathname(site.options, :output_dir)
         | 
| 94 102 | 
             
              builder = Hx::FileBuilder.new(output_dir.to_s)
         | 
| 95 103 | 
             
              site.each_entry do |path, entry|
         | 
| 96 104 | 
             
                puts "===> #{path}"
         | 
| 97 | 
            -
                 | 
| 105 | 
            +
                if update_only
         | 
| 106 | 
            +
                  builder.build_file_if_updated(path, entry)
         | 
| 107 | 
            +
                else
         | 
| 108 | 
            +
                  builder.build_file(path, entry)
         | 
| 109 | 
            +
                end
         | 
| 98 110 | 
             
              end
         | 
| 99 111 | 
             
            end
         | 
| 100 112 |  | 
| @@ -56,9 +56,9 @@ class RecursiveIndex | |
| 56 56 | 
             
                    index_path = (components + ["index"]).join("/")
         | 
| 57 57 | 
             
                    index = indexes[index_path]
         | 
| 58 58 | 
             
                    index['items'] << {'path' => path, 'entry' => entry}
         | 
| 59 | 
            -
                    if entry[' | 
| 60 | 
            -
                       (not index[' | 
| 61 | 
            -
                      index[' | 
| 59 | 
            +
                    if entry['updated'] and
         | 
| 60 | 
            +
                       (not index['updated'] or entry['updated'] > index['updated'])
         | 
| 61 | 
            +
                      index['updated'] = entry['updated']
         | 
| 62 62 | 
             
                    end
         | 
| 63 63 | 
             
                  end
         | 
| 64 64 | 
             
                end
         | 
| @@ -85,12 +85,14 @@ class LiquidTemplate | |
| 85 85 | 
             
                    output_path = path
         | 
| 86 86 | 
             
                  end
         | 
| 87 87 | 
             
                  output_entry = entry.dup
         | 
| 88 | 
            -
                  output_entry['content'] =  | 
| 89 | 
            -
                     | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 88 | 
            +
                  output_entry['content'] = Hx::LazyContent.new do
         | 
| 89 | 
            +
                    @template.render(
         | 
| 90 | 
            +
                      'now' => Time.now,
         | 
| 91 | 
            +
                      'options' => @options,
         | 
| 92 | 
            +
                      'path' => path,
         | 
| 93 | 
            +
                      'entry' => entry
         | 
| 94 | 
            +
                    )
         | 
| 95 | 
            +
                  end
         | 
| 94 96 | 
             
                  yield output_path, output_entry
         | 
| 95 97 | 
             
                end
         | 
| 96 98 | 
             
                self
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: hx
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.5.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - MenTaLguY
         | 
| @@ -9,7 +9,7 @@ autorequire: | |
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 |  | 
| 12 | 
            -
            date: 2010-02- | 
| 12 | 
            +
            date: 2010-02-07 00:00:00 -05:00
         | 
| 13 13 | 
             
            default_executable: 
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -22,7 +22,11 @@ dependencies: | |
| 22 22 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 23 23 | 
             
                    version: 1.2.9
         | 
| 24 24 | 
             
                version: 
         | 
| 25 | 
            -
            description:  | 
| 25 | 
            +
            description: |
         | 
| 26 | 
            +
              Hx is a simple static site generator in the spirit of Hobix which reads a
         | 
| 27 | 
            +
              YAML configuration file, constructs a filter graph, and generates output
         | 
| 28 | 
            +
              files.
         | 
| 29 | 
            +
             | 
| 26 30 | 
             
            email: mental@rydia.net
         | 
| 27 31 | 
             
            executables: 
         | 
| 28 32 | 
             
            - hx
         | 
| @@ -85,7 +89,7 @@ rubyforge_project: | |
| 85 89 | 
             
            rubygems_version: 1.3.5
         | 
| 86 90 | 
             
            signing_key: 
         | 
| 87 91 | 
             
            specification_version: 3
         | 
| 88 | 
            -
            summary: A miniature site generator.
         | 
| 92 | 
            +
            summary: A miniature static site generator.
         | 
| 89 93 | 
             
            test_files: 
         | 
| 90 94 | 
             
            - spec/spec_helper.rb
         | 
| 91 95 | 
             
            - spec/cache_spec.rb
         |