Merge: nitrpg: update the userscript to the new github layout and fix todos
authorJean Privat <jean@pryen.org>
Thu, 26 Nov 2015 18:52:33 +0000 (13:52 -0500)
committerJean Privat <jean@pryen.org>
Thu, 26 Nov 2015 18:52:33 +0000 (13:52 -0500)
Basically a rewrite, but it works on my computer

Pull-Request: #1849
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

contrib/inkscape_tools/src/svg_to_icons.nit
lib/curl/curl.nit
lib/curl/examples/curl_http.nit
lib/neo4j/curl_json.nit
lib/neo4j/neo4j.nit
src/model/model.nit

index 301772b..917c197 100644 (file)
@@ -20,8 +20,7 @@ module svg_to_icons
 import opts
 
 redef class Int
-       fun android_path: String do return "drawable-{resolution_name}/icon.png"
-
+       # Android name for this resolution
        fun resolution_name: String
        do
                if self == 36 then return "ldpi"
@@ -37,11 +36,12 @@ end
 var opt_out = new OptionString("Where to output PNG files", "--out", "-o")
 var opt_id = new OptionString("Extract only object with given ID", "--id", "-i")
 var opt_android = new OptionBool("Generate in the file structure for Android", "--android", "-a")
+var opt_android_name = new OptionString("Name of the resource for Android", "--name", "-n")
 var opt_large = new OptionBool("Generate large icons (512 and 1024 px)", "--large", "-l")
 var opt_help = new OptionBool("Print this help message", "--help", "-h")
 
 var opt_context = new OptionContext
-opt_context.add_option(opt_out, opt_id, opt_android, opt_large, opt_help)
+opt_context.add_option(opt_out, opt_id, opt_android, opt_android_name, opt_large, opt_help)
 
 opt_context.parse(args)
 var rest = opt_context.rest
@@ -83,10 +83,12 @@ else if opt_large.value then
        resolutions = [512, 1024]
 else abort
 
+var android_res_name = opt_android_name.value or else "icon"
+
 for wh in resolutions do
        var png_path
        if opt_android.value then
-               png_path = "{out_path}/{wh.android_path}"
+               png_path = out_path / "drawable-" + wh.resolution_name / android_res_name + ".png"
                var dir = png_path.dirname
                if not dir.file_exists then dir.mkdir
        else
index f225a02..6ae0b9a 100644 (file)
@@ -73,20 +73,46 @@ class CurlRequest
        end
 end
 
-# CURL HTTP Request
+# HTTP request builder
+#
+# The request itself is sent by either `execute` or `download_to_file`.
+# The attributes of this class must be set before calling either of these two methods.
+#
+# ## Minimal usage example
+#
+# ~~~
+# var request = new CurlHTTPRequest("http://example.org/")
+# var response = request.execute
+# if response isa CurlResponseSuccess then
+#     print "Response status code: {response.status_code}"
+#     print response.body_str
+# else if response isa CurlResponseFailed then
+#     print_error response.error_msg
+# end
+# ~~~
 class CurlHTTPRequest
        super CurlRequest
        super NativeCurlCallbacks
 
+       # Address of the remote resource to request
        var url: String
-       var datas: nullable HeaderMap is writable
+
+       # Data for the body of a POST request
+       var data: nullable HeaderMap is writable
+
+       # Header content of the request
        var headers: nullable HeaderMap is writable
+
+       # Delegates to customize the behavior when running `execute`
        var delegate: nullable CurlCallbacks is writable
 
        # Set the user agent for all following HTTP requests
        var user_agent: nullable String is writable
 
-       # Execute HTTP request with settings configured through attribute
+       # Execute HTTP request
+       #
+       # By default, the response body is returned in an instance of `CurlResponse`.
+       # This behavior can be customized by setting a custom `delegate`.
        fun execute: CurlResponse
        do
                if not self.curl.is_ok then return answer_failure(0, "Curl instance is not correctly initialized")
@@ -125,9 +151,9 @@ class CurlHTTPRequest
                end
 
                # Datas
-               var datas = self.datas
-               if datas != null then
-                       var postdatas = datas.to_url_encoded(self.curl)
+               var data = self.data
+               if data != null then
+                       var postdatas = data.to_url_encoded(self.curl)
                        err = self.curl.native.easy_setopt(new CURLOption.postfields, postdatas)
                        if not err.is_ok then return answer_failure(err.to_i, err.to_s)
                end
index d19ee96..9eed5b8 100644 (file)
@@ -64,11 +64,11 @@ else if args[0] == "POST" then
        var my_http_fetcher = new MyHttpFetcher
        request.delegate = my_http_fetcher
 
-       var post_datas = new HeaderMap
-       post_datas["Bugs Bunny"] = "Daffy Duck"
-       post_datas["Batman"] = "Robin likes special characters @#ùà!è§'(\"é&://,;<>∞~*"
-       post_datas["Batman"] = "Yes you can set multiple identical keys, but APACHE will consider only one, the last one"
-       request.datas = post_datas
+       var post_data = new HeaderMap
+       post_data["Bugs Bunny"] = "Daffy Duck"
+       post_data["Batman"] = "Robin likes special characters @#ùà!è§'(\"é&://,;<>∞~*"
+       post_data["Batman"] = "Yes you can set multiple identical keys, but APACHE will consider only one, the last one"
+       request.data = post_data
        var response = request.execute
 
        print "Our body from the callback: {my_http_fetcher.fetched_body}"
index 17df2fc..03a7ca4 100644 (file)
@@ -106,7 +106,7 @@ end
 class JsonPOST
        super JsonCurlRequest
 
-       var data: nullable Jsonable = null is writable
+       var json_data: nullable Jsonable = null is writable
 
        redef fun init_headers do
                super
@@ -117,8 +117,8 @@ class JsonPOST
                var err = self.curl.native.easy_setopt(new CURLOption.post, true)
                if not err.is_ok then return answer_failure(err.to_i, err.to_s)
 
-               if self.data != null then
-                       var postdatas = self.data.to_json
+               if self.json_data != null then
+                       var postdatas = self.json_data.to_json
                        err = self.curl.native.easy_setopt(new CURLOption.postfields, postdatas)
                        if not err.is_ok then return answer_failure(err.to_i, err.to_s)
                end
@@ -141,7 +141,7 @@ end
 class JsonPUT
        super JsonCurlRequest
 
-       var data: nullable Jsonable = null is writable
+       var json_data: nullable Jsonable = null is writable
 
        redef fun init_headers do
                super
@@ -152,8 +152,8 @@ class JsonPUT
                var err = self.curl.native.easy_setopt(new CURLOption.custom_request, "PUT")
                if not err.is_ok then return answer_failure(err.to_i, err.to_s)
 
-               if self.data != null then
-                       var postdatas = self.data.to_json
+               if self.json_data != null then
+                       var postdatas = self.json_data.to_json
                        err = self.curl.native.easy_setopt(new CURLOption.postfields, postdatas)
                        if not err.is_ok then return answer_failure(err.to_i, err.to_s)
                end
index 9f96118..c6c005a 100644 (file)
@@ -328,7 +328,7 @@ class Neo4jClient
        # POST `params` to `url`
        fun post(url: String, params: Jsonable): Jsonable do
                var request = new JsonPOST(url)
-               request.data = params
+               request.json_data = params
                var response = request.execute
                return parse_response(response)
        end
@@ -336,7 +336,7 @@ class Neo4jClient
        # PUT `params` at `url`
        fun put(url: String, params: Jsonable): Jsonable do
                var request = new JsonPUT(url)
-               request.data = params
+               request.json_data = params
                var response = request.execute
                return parse_response(response)
        end
@@ -916,7 +916,7 @@ class NeoBatch
                # request.headers["X-Stream"] = "true"
                var json_jobs = new JsonArray
                for job in jobs.values do json_jobs.add job.to_rest
-               request.data = json_jobs
+               request.json_data = json_jobs
                var response = request.execute
                var res = client.parse_response(response)
                return finalize_batch(res)
index 49ababd..b9d6aa2 100644 (file)
@@ -300,18 +300,15 @@ redef class MModule
                var props = self.model.get_mproperties_by_name(name)
                if props == null then return null
                var res: nullable MMethod = null
+               var recvtype = recv.intro.bound_mtype
                for mprop in props do
                        assert mprop isa MMethod
-                       var intro = mprop.intro_mclassdef
-                       for mclassdef in recv.mclassdefs do
-                               if not self.in_importation.greaters.has(mclassdef.mmodule) then continue
-                               if not mclassdef.in_hierarchy.greaters.has(intro) then continue
-                               if res == null then
-                                       res = mprop
-                               else if res != mprop then
-                                       print("Fatal Error: ambigous property name '{name}'; conflict between {mprop.full_name} and {res.full_name}")
-                                       abort
-                               end
+                       if not recvtype.has_mproperty(self, mprop) then continue
+                       if res == null then
+                               res = mprop
+                       else if res != mprop then
+                               print("Fatal Error: ambigous property name '{name}'; conflict between {mprop.full_name} and {res.full_name}")
+                               abort
                        end
                end
                return res