tidy_ffi 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ before_install:
2
+ - sudo apt-get update -qq
3
+ - sudo apt-get install -qq libtidy-dev
4
+ rvm:
5
+ - 1.8.7
6
+ - ree
7
+ - 1.9.3
8
+ - jruby-18mode
9
+ - jruby-19mode
data/CHANGELOG CHANGED
@@ -1,4 +1,5 @@
1
- v0.1.4. Correct the way libtidy is located on the filesystem. Works if libtidy resides in /usr/lib64, instead of /usr/lib
1
+ v0.1.5. Fix JRuby issues.
2
+ v0.1.4. Fix the way libtidy is located on the filesystem. Works if libtidy is in /usr/lib64, instead of /usr/lib
2
3
  v0.1.3. Fix recognition of date on weird environments
3
4
  v0.1.2. Initialize buffer before use
4
5
  v0.1.1. Fixes for new version of FFI gem
data/README.rdoc CHANGED
@@ -2,20 +2,20 @@
2
2
 
3
3
  == What is it all about?
4
4
 
5
- I wanna clean and simple tidy library. For example:
5
+ I wanted to have a clean and simple tidy library. For example:
6
6
  TidyFFI::Tidy.new('a string').clean
7
7
 
8
8
  For now it can't do anything else than clean (and saves errors from it) :)
9
9
 
10
10
  == Options
11
11
 
12
- You can use different ways to set up options. These examples are produces the same output:
12
+ You can use different ways to specify options. These examples produce the same output:
13
13
 
14
14
  TidyFFI::Tidy.default_options.show_body_only = true
15
15
  TidyFFI::Tidy.new('test').clean
16
-
16
+
17
17
  TidyFFI::Tidy.with_options(:show_body_only => true).new('test').clean
18
-
18
+
19
19
  tidy = TidyFFI::Tidy.new('test')
20
20
  tidy.options.show_body_only = true
21
21
  tidy.clean
@@ -24,8 +24,6 @@ You can use different ways to set up options. These examples are produces the sa
24
24
 
25
25
  TidyFFI::Tidy.clean('test', :show_body_only => 1)
26
26
 
27
- == Links
27
+ == Other stuff
28
28
 
29
- * Source code: http://github.com/libc/tidy_ffi
30
- * Bug tracker: http://rubyforge.org/tracker/?atid=30230&group_id=7805&func=browse
31
- * Rubyforge project: http://rubyforge.org/projects/tidy-ffi
29
+ And of course, it's depenedent on ffi and libtidy. So make sure they're installed before using the library!
@@ -100,18 +100,19 @@ class TidyFFI::Interface
100
100
 
101
101
  pick_list = []
102
102
 
103
- FFI::MemoryPointer.new(:pointer, 1) do |pointer|
104
- pointer.put_pointer(0, iterator)
105
- until iterator.null?
106
- pick_list << LibTidy.tidyOptGetNextPick(opt, pointer)
107
- iterator = pointer.get_pointer(0)
108
- end
103
+ pointer = FFI::MemoryPointer.new(:pointer, 1)
104
+ pointer.put_pointer(0, iterator)
105
+ until iterator.null?
106
+ pick_list << LibTidy.tidyOptGetNextPick(opt, pointer)
107
+ iterator = pointer.get_pointer(0)
109
108
  end
110
109
 
111
110
  pick_list
111
+ ensure
112
+ pointer.free if pointer
112
113
  end
113
114
  private :pick_list_for
114
-
115
+
115
116
  # Loads default options.
116
117
  def load_default_options
117
118
  return if @default_options
@@ -121,40 +122,40 @@ class TidyFFI::Interface
121
122
 
122
123
  @default_options = {}
123
124
 
124
- FFI::MemoryPointer.new(:pointer, 1) do |pointer|
125
- pointer.put_pointer(0, iterator)
126
-
127
- until iterator.null?
128
- opt = LibTidy.tidyGetNextOption(doc, pointer)
129
-
130
- option = {}
131
-
132
- option[:name] = LibTidy.tidyOptGetName(opt).gsub('-', '_').intern
133
- option[:readonly?] = LibTidy.tidyOptIsReadOnly(opt) != 0
134
- option[:type] = LibTidy::TIDY_OPTION_TYPE[LibTidy.tidyOptGetType(opt)]
135
- option[:default] = case option[:type]
136
- when :string
137
- (LibTidy.tidyOptGetDefault(opt) rescue "")
138
- when :integer
139
- if pick_list = pick_list_for(opt)
140
- option[:type] = :enum
141
- option[:values] = pick_list
142
- pick_list[LibTidy.tidyOptGetDefaultInt(opt)]
143
- else
144
- LibTidy.tidyOptGetDefaultInt(opt)
145
- end
146
- when :boolean
147
- LibTidy.tidyOptGetDefaultBool(opt) != 0
125
+ pointer = FFI::MemoryPointer.new(:pointer, 1)
126
+ pointer.put_pointer(0, iterator)
127
+
128
+ until iterator.null?
129
+ opt = LibTidy.tidyGetNextOption(doc, pointer)
130
+
131
+ option = {}
132
+
133
+ option[:name] = LibTidy.tidyOptGetName(opt).gsub('-', '_').intern
134
+ option[:readonly?] = LibTidy.tidyOptIsReadOnly(opt) != 0
135
+ option[:type] = LibTidy::TIDY_OPTION_TYPE[LibTidy.tidyOptGetType(opt)]
136
+ option[:default] = case option[:type]
137
+ when :string
138
+ (LibTidy.tidyOptGetDefault(opt) rescue "")
139
+ when :integer
140
+ if pick_list = pick_list_for(opt)
141
+ option[:type] = :enum
142
+ option[:values] = pick_list
143
+ pick_list[LibTidy.tidyOptGetDefaultInt(opt)]
144
+ else
145
+ LibTidy.tidyOptGetDefaultInt(opt)
148
146
  end
149
-
150
- @default_options[option[:name]] = option
151
-
152
- iterator = pointer.get_pointer(0)
147
+ when :boolean
148
+ LibTidy.tidyOptGetDefaultBool(opt) != 0
153
149
  end
154
150
 
151
+ @default_options[option[:name]] = option
152
+
153
+ iterator = pointer.get_pointer(0)
155
154
  end
155
+
156
156
  @default_options.freeze
157
157
  ensure
158
+ pointer.free if pointer
158
159
  LibTidy.tidyRelease(doc)
159
160
  end
160
161
  private :load_default_options
@@ -171,11 +172,12 @@ class TidyFFI::Interface
171
172
  def self.default_options
172
173
  @default_options ||= load_default_options
173
174
  end
174
-
175
+
175
176
  # Returns true if value is valid for +option+ and false otherwise.
176
177
  def self.option_valid?(option, value)
177
- return false unless spec = default_options[option]
178
-
178
+ spec = default_options[option]
179
+ return false unless spec
180
+
179
181
  case spec[:type]
180
182
  when :boolean
181
183
  true == value || false == value || value == 0 || value == 1 || %w(on off true false 0 1 yes no).include?(value.downcase)
@@ -185,10 +187,10 @@ class TidyFFI::Interface
185
187
  if Integer === value
186
188
  !!spec[:values][value]
187
189
  else
188
- spec[:values].include?(value)
190
+ spec[:values].include?(value.downcase)
189
191
  end
190
192
  when :string
191
193
  String === value || Symbol === value
192
194
  end
193
195
  end
194
- end
196
+ end
@@ -3,7 +3,14 @@
3
3
  # This file must be lazy loaded!
4
4
  class TidyFFI::LibTidy #:nodoc:
5
5
  extend FFI::Library
6
- ffi_lib TidyFFI.library_path
6
+
7
+ paths = Array(TidyFFI.library_path || Dir['/{opt,usr}/{,local/}lib{,64}/libtidy{,-*}.{dylib,so*}'])
8
+ begin
9
+ ffi_lib(*paths)
10
+ rescue LoadError
11
+ raise TidyFFI::LibTidyNotInstalled, "didn't find tidy libs on your system. Please install tidy (http://tidy.sourceforge.net/)"
12
+ end
13
+
7
14
 
8
15
  attach_function :tidyReleaseDate, [], :string
9
16
 
@@ -48,12 +48,12 @@ class TidyFFI::OptionsContainer #:nodoc:
48
48
  # It's a kinda bad method: it uses TidyFFI::Interface.option_valid and TidyFFI::Tidy.validate_options?
49
49
  # Also it do second lookup into default options
50
50
  def validate_option(key, value)
51
- if TidyFFI::Tidy.validate_options? && !TidyFFI::Interface.option_valid?(key, value)
52
- if TidyFFI::Interface.default_options[key]
53
- raise TidyFFI::Tidy::InvalidOptionValue, "#{value} is not valid for #{key}"
54
- else
55
- raise TidyFFI::Tidy::InvalidOptionName, "#{key} is invalid option name"
56
- end
51
+ return if !TidyFFI::Tidy.validate_options? || TidyFFI::Interface.option_valid?(key, value)
52
+
53
+ if TidyFFI::Interface.default_options[key]
54
+ raise TidyFFI::Tidy::InvalidOptionValue, "#{value} is not a valid value for key #{key}"
55
+ else
56
+ raise TidyFFI::Tidy::InvalidOptionName, "#{key} is an invalid option name"
57
57
  end
58
58
  end
59
59
 
@@ -87,4 +87,4 @@ class TidyFFI::OptionsContainer #:nodoc:
87
87
  @obj.send(meth, *args)
88
88
  end
89
89
  end
90
- end
90
+ end
@@ -1,12 +1,5 @@
1
1
  module TidyFFI::TidyFFIExtensions #:nodoc:
2
- # Sets path to libtidy.{dylib,so}
3
- def library_path=(path)
4
- @libtidy_path = path
5
- end
6
-
7
- # Returns path to libtidy.{dylib,so}
8
- def library_path
9
- @libtidy_path ||= 'tidy'
10
- end
2
+ # Sets and gets path to libtidy.{dylib,so}
3
+ attr_accessor :library_path
11
4
  end
12
5
  TidyFFI.extend TidyFFI::TidyFFIExtensions
@@ -1,3 +1,3 @@
1
1
  module TidyFFI
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/spec/simple_spec.rb CHANGED
@@ -46,8 +46,13 @@ describe TidyFFI::Tidy do
46
46
  it "raises error on invalid option value" do
47
47
  TidyFFI::Tidy.validate_options = true
48
48
  lambda do
49
- TidyFFI::Tidy.default_options = {:force_output => "utter trash"}
49
+ TidyFFI::Tidy.default_options = {:force_output => "utter garbage"}
50
50
  end.should raise_error(TidyFFI::Tidy::InvalidOptionValue)
51
51
  end
52
+
53
+ it 'accepts UTF-8 writter in uppercase' do
54
+ TidyFFI::Tidy.validate_options = true
55
+ expect { TidyFFI::Tidy.default_options = {:char_encoding => "UTF8"} }.not_to raise_error
56
+ end
52
57
  end
53
- end
58
+ end
data/tidy_ffi.gemspec CHANGED
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency 'ffi', ">= 0.3.5"
21
+ s.add_dependency 'ffi', "~> 1.2.0"
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tidy_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,19 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-13 00:00:00.000000000 Z
12
+ date: 2012-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
- requirement: &70164966260060 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.3.5
21
+ version: 1.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70164966260060
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.0
25
30
  description: Tidy library interface via FFI
26
31
  email: libc@libc.st
27
32
  executables: []
@@ -30,6 +35,7 @@ extra_rdoc_files: []
30
35
  files:
31
36
  - .gitignore
32
37
  - .rspec
38
+ - .travis.yml
33
39
  - CHANGELOG
34
40
  - Gemfile
35
41
  - LICENSE
@@ -62,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
68
  version: '0'
63
69
  segments:
64
70
  - 0
65
- hash: 4149357649508067802
71
+ hash: 3224835435869118634
66
72
  required_rubygems_version: !ruby/object:Gem::Requirement
67
73
  none: false
68
74
  requirements:
@@ -71,10 +77,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
77
  version: '0'
72
78
  segments:
73
79
  - 0
74
- hash: 4149357649508067802
80
+ hash: 3224835435869118634
75
81
  requirements: []
76
82
  rubyforge_project: tidy-ffi
77
- rubygems_version: 1.8.10
83
+ rubygems_version: 1.8.24
78
84
  signing_key:
79
85
  specification_version: 3
80
86
  summary: Tidy library interface via FFI